{"id":1643,"url":"https://github.com/azawawi/SwiftyZeroMQ","last_synced_at":"2025-08-02T04:32:19.941Z","repository":{"id":62457036,"uuid":"71238241","full_name":"azawawi/SwiftyZeroMQ","owner":"azawawi","description":"ZeroMQ Swift Bindings for iOS, macOS, tvOS and watchOS","archived":false,"fork":false,"pushed_at":"2019-04-05T11:08:59.000Z","size":31948,"stargazers_count":64,"open_issues_count":9,"forks_count":42,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-07-05T21:02:00.367Z","etag":null,"topics":["ios","macos","swift","tvos","watchos","zeromq"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/azawawi.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-10-18T10:46:55.000Z","updated_at":"2025-06-10T06:48:33.000Z","dependencies_parsed_at":"2022-11-01T23:03:53.847Z","dependency_job_id":null,"html_url":"https://github.com/azawawi/SwiftyZeroMQ","commit_stats":null,"previous_names":[],"tags_count":26,"template":false,"template_full_name":null,"purl":"pkg:github/azawawi/SwiftyZeroMQ","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azawawi%2FSwiftyZeroMQ","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azawawi%2FSwiftyZeroMQ/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azawawi%2FSwiftyZeroMQ/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azawawi%2FSwiftyZeroMQ/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/azawawi","download_url":"https://codeload.github.com/azawawi/SwiftyZeroMQ/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azawawi%2FSwiftyZeroMQ/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268334615,"owners_count":24233793,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-02T02:00:12.353Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ios","macos","swift","tvos","watchos","zeromq"],"created_at":"2024-01-05T20:15:52.147Z","updated_at":"2025-08-02T04:32:17.990Z","avatar_url":"https://github.com/azawawi.png","language":"Swift","funding_links":[],"categories":["Networking"],"sub_categories":["Video","Other free courses"],"readme":"# SwiftyZeroMQ - ZeroMQ Swift Bindings for iOS, macOS, tvOS and watchOS\n\n[![CI Status][travis-badge]][travis-url]\n[![Swift][swift-badge]][swift-url]\n[![ZeroMQ][zeromq-badge]][zeromq-url]\n[![Platform][platform-badge]][platform-url]\n[![Carthage][carthage-badge]][carthage-url]\n[![CocoaPods][cocoapods-badge]][cocoapods-url]\n[![License][mit-badge]][mit-url]\n\nThis library provides easy-to-use iOS, macOS, tvOS and watchOS\n[Swift](http://swift.org) bindings for the [ZeroMQ](http://zeromq.org) C++\nlibrary. It is written in Swift 3 and features a bundled stable\n[`libzmq`](https://github.com/zeromq/libzmq) library. It provides ZeroMQ's\nlow-level API along with an object-oriented API.\n\n## What is ZeroMQ?\n\n\u003e ZeroMQ (also spelled ØMQ, 0MQ or ZMQ) is a high-performance asynchronous\n\u003e messaging library, aimed at use in distributed or concurrent applications. It\n\u003e provides a message queue, but unlike message-oriented middleware, a ZeroMQ\n\u003e system can run without a dedicated message broker. The library's API is\n\u003e designed to resemble that of Berkeley sockets.\n\n## Requirements\n\n- iOS 9+ / macOS 10.11+ / tvOS 9.0+ / watchOS 2.0+\n- Xcode 8.1 and Swift 3.0\n- Bitcode-enabled Xcode project for non-MacOS\n\n## Usage\n\nPlease consult the [**Documentation Manual**](Documentation/Manual.md) for more\ninformation. Older examples can also be found in the\n[examples](https://github.com/azawawi/swift-zmq-examples) github repository.\n\n### Version\n\n```swift\nimport SwiftyZeroMQ\n\n// Print ZeroMQ library and our framework version\nlet (major, minor, patch, versionString) = SwiftyZeroMQ.version\nprint(\"ZeroMQ library version is \\(major).\\(minor) with patch level .\\(patch)\")\nprint(\"ZeroMQ library version is \\(versionString)\")\nprint(\"SwiftyZeroMQ version is \\(SwiftyZeroMQ.frameworkVersion)\")\n```\n\n### Request-reply Pattern\n\n```swift\nimport SwiftyZeroMQ\n\ndo {\n    // Define a TCP endpoint along with the text that we are going to send/recv\n    let endpoint     = \"tcp://127.0.0.1:5555\"\n    let textToBeSent = \"Hello world\"\n\n    // Request socket\n    let context      = try SwiftyZeroMQ.Context()\n    let requestor    = try context.socket(.request)\n    try requestor.connect(endpoint)\n\n    // Reply socket\n    let replier      = try context.socket(.reply)\n    try replier.bind(endpoint)\n\n    // Send it without waiting and check the reply on other socket\n    try requestor.send(string: textToBeSent, options: .dontWait)\n    let reply = try replier.recv()\n    if reply == textToBeSent {\n        print(\"Match\")\n    } else {\n        print(\"Mismatch\")\n    }\n\n} catch {\n    print(error)\n}\n```\n\n### Publish-Subscribe Pattern\n\n```swift\nprivate let endpoint = \"tcp://127.0.0.1:5550\"\n\nlet context      = try SwiftyZeroMQ.Context()\nlet publisher    = try context.socket(.publish)\nlet subscriber1  = try context.socket(.subscribe)\nlet subscriber2  = try context.socket(.subscribe)\nlet subscriber3  = try context.socket(.subscribe)\n\ntry publisher.bind(endpoint)\nlet subscribers = [\n    subscriber1: \"Subscriber #1\",\n    subscriber2: \"Subscriber #2\",\n    subscriber3: \"Subscriber #3\",\n]\ntry subscriber1.connect(endpoint)\ntry subscriber2.connect(endpoint)\ntry subscriber3.connect(endpoint)\n\n// Brief wait to let everything hook up\nusleep(1000)\n\n// Subscriber #1 and #2 should receive anything\ntry subscriber2.setSubscribe(nil)\n\n// Subscriber #3 should receive only messages starting with \"topic\"\ntry subscriber3.setSubscribe(\"topic\")\n\n// Brief wait to let everything hook up\nusleep(250)\n\nlet poller = SwiftyZeroMQ.Poller()\ntry poller.register(socket: subscriber1, flags: .pollIn)\ntry poller.register(socket: subscriber2, flags: .pollIn)\ntry poller.register(socket: subscriber3, flags: .pollIn)\n\nfunc pollAndRecv() throws {\n    let socks = try poller.poll(timeout: 1000)\n    for subscriber in socks.keys {\n        let name = subscribers[subscriber]\n        if socks[subscriber] == SwiftyZeroMQ.PollFlags.pollIn {\n            let text = try subscriber.recv(options: .dontWait)\n            print(\"\\(name): received '\\(text)'\")\n        } else {\n            print(\"\\(name): Nothing\")\n        }\n    }\n    print(\"---\")\n}\n\n// Send a message - expect only sub2 to receive\ntry publisher.send(string: \"message\")\n\n// Wait a bit to let the message come through\nusleep(100)\n\ntry pollAndRecv();\n\n// Send a message - sub2 and sub3 should receive\ntry publisher.send(string: \"topic: test\")\n\n// Wait a bit to let the message come through\nusleep(100)\n\ntry pollAndRecv();\n```\n\n### Poller\n\n```swift\nimport SwiftyZeroMQ\n\ndo {\n    // Define a TCP endpoint along with the text that we are going to send/recv\n    let endpoint     = \"tcp://127.0.0.1:5555\"\n\n    // Request socket\n    let context      = try SwiftyZeroMQ.Context()\n    let requestor    = try context.socket(.request)\n    try requestor.connect(endpoint)\n\n    // Reply socket\n    let replier      = try context.socket(.reply)\n    try replier.bind(endpoint)\n\n    // Create a Poller and add both requestor and replier\n    let poller       = SwiftyZeroMQ.Poller()\n    try poller.register(socket: requestor, flags: [.pollIn, .pollOut])\n    try poller.register(socket: replier, flags: [.pollIn, .pollOut])\n\n    try requestor.send(string: \"Hello replier!\")\n\n    // wait to let request come through\n    sleep(1)\n\n    var updates = try poller.poll()\n    if updates[replier] == SwiftyZeroMQ.PollFlags.pollIn {\n        print(\"Replier has data to be received.\")\n    }\n    else {\n        print(\"Expected replier to be in pollIn state.\")\n        return\n    }\n\n    try _ = replier.recv()\n\n    updates = try poller.poll()\n    if updates[replier] == SwiftyZeroMQ.PollFlags.none {\n        print(\"All data has been received\")\n    }\n    else {\n        print(\"Expected replier to be in none state.\")\n        return\n    }\n} catch {\n    print(error)\n}\n```\n\n## Planned Features (aka TODO)\n\n- [ ] More official ZeroMQ examples written\n- [ ] More ZeroMQ API wrapped\n\n## See Also\n\n- For Linux and macOS support with SwiftPM, please see [Zewo's ZeroMQ Swift bindings](https://github.com/ZewoGraveyard/ZeroMQ).\n\n## Author \u0026 License\n\nCopyright (c) 2016-2017 [Ahmad M. Zawawi](https://github.com/azawawi) under the\n[MIT license](LICENSE).\n\nA prebuilt iOS, macOS, tvOS and watchOS universal\n[`libzmq`](https://github.com/zeromq/libzmq) library is bundled with this\nlibrary under the [LGPL](https://github.com/zeromq/libzmq#license) license.\n\n[travis-badge]: https://travis-ci.org/azawawi/SwiftyZeroMQ.svg?branch=master\n[travis-url]: https://travis-ci.org/azawawi/SwiftyZeroMQ\n\n[swift-badge]: https://img.shields.io/badge/Swift-3.0-orange.svg?style=flat\n[swift-url]: https://swift.org\n\n[zeromq-badge]: https://img.shields.io/badge/ZeroMQ-4.2.1-blue.svg?style=flat\n[zeromq-url]: https://zeromq.org\n\n[platform-badge]: https://img.shields.io/badge/Platforms-iOS%20|%20macOS%20|%20tvOS%20|%20watchOS-blue.svg?style=flat\n[platform-url]: http://cocoadocs.org/docsets/SwiftyZeroMQ\n\n[carthage-badge]: https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat\n[carthage-url]: https://github.com/Carthage/Carthage\n\n[cocoapods-badge]: https://img.shields.io/cocoapods/v/SwiftyZeroMQ.svg\n[cocoapods-url]: https://cocoapods.org/?q=swiftyzeromq\n\n[mit-badge]: https://img.shields.io/badge/License-MIT-blue.svg?style=flat\n[mit-url]: https://tldrlegal.com/license/mit-license\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fazawawi%2FSwiftyZeroMQ","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fazawawi%2FSwiftyZeroMQ","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fazawawi%2FSwiftyZeroMQ/lists"}