{"id":3095,"url":"https://github.com/tidwall/SwiftWebSocket","last_synced_at":"2025-08-06T14:31:36.429Z","repository":{"id":32730748,"uuid":"36320857","full_name":"tidwall/SwiftWebSocket","owner":"tidwall","description":"Fast Websockets in Swift for iOS and OSX","archived":true,"fork":false,"pushed_at":"2021-08-19T15:47:35.000Z","size":4684,"stargazers_count":1530,"open_issues_count":64,"forks_count":245,"subscribers_count":52,"default_branch":"master","last_synced_at":"2024-05-22T06:01:41.121Z","etag":null,"topics":["networking"],"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/tidwall.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":"2015-05-26T20:07:41.000Z","updated_at":"2024-05-16T10:49:49.000Z","dependencies_parsed_at":"2022-09-11T15:21:11.628Z","dependency_job_id":null,"html_url":"https://github.com/tidwall/SwiftWebSocket","commit_stats":null,"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tidwall%2FSwiftWebSocket","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tidwall%2FSwiftWebSocket/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tidwall%2FSwiftWebSocket/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tidwall%2FSwiftWebSocket/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tidwall","download_url":"https://codeload.github.com/tidwall/SwiftWebSocket/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":214952814,"owners_count":15807834,"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","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":["networking"],"created_at":"2024-01-05T20:16:31.242Z","updated_at":"2024-08-17T16:31:11.632Z","avatar_url":"https://github.com/tidwall.png","language":"Swift","funding_links":[],"categories":["WebSocket","Libs","Networking","Swift","HTTP","Network [🔝](#readme)","iOS","Networking and Distributed"],"sub_categories":["Web View","Network","Other free courses","Socket","Networking"],"readme":"# \u003cimg src=\"/tools/res/logo.png\" height=\"45\" width=\"60\"\u003e\u0026nbsp;SwiftWebSocket\n\n[![API Docs](https://img.shields.io/badge/api-docs-blue.svg?style=flat-square)](http://tidwall.com/SwiftWebSocket/docs/)\n[![Swift/5.0](https://img.shields.io/badge/swift-5.0-brightgreen.svg?style=flat-square)](https://developer.apple.com/swift/)\n[![Build Status](https://img.shields.io/badge/build-passing-brightgreen.svg?style=flat-square)](http://tidwall.com/SwiftWebSocket/results/)\n\nConforming WebSocket ([RFC 6455](https://tools.ietf.org/html/rfc6455)) client library for iOS and Mac OSX.\n\nSwiftWebSocket passes all 521 of the Autobahn's fuzzing tests, including strict UTF-8, and message compression.\n\n### `Project Status`\n\nI'm looking for someone to help with or take over maintenance of this project.\n\n## Features\n\n- High performance.\n- 100% conforms to [Autobahn Tests](http://autobahn.ws/testsuite/#test-suite-coverage). Including base, limits, compression, etc. [Test results](https://tidwall.github.io/SwiftWebSocket/results/).\n- TLS / WSS support. Self-signed certificate option.\n- The API is modeled after the [Javascript API](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket).\n- Reads compressed messages (`permessage-deflate`). [RFC 7692](https://tools.ietf.org/html/rfc7692)\n- Send pings and receive pong events.\n- Strict UTF-8 processing. \n- `binaryType` property to choose between `[UInt8]` or `NSData` messages.\n- Zero asserts. All networking, stream, and protocol errors are routed through the `error` event.\n- iOS / Objective-C support.\n\n## Example\n\n```swift\nfunc echoTest(){\n    var messageNum = 0\n    let ws = WebSocket(\"wss://echo.websocket.org\")\n    let send : ()-\u003e() = {\n        messageNum += 1\n        let msg = \"\\(messageNum): \\(NSDate().description)\"\n        print(\"send: \\(msg)\")\n        ws.send(msg)\n    }\n    ws.event.open = {\n        print(\"opened\")\n        send()\n    }\n    ws.event.close = { code, reason, clean in\n        print(\"close\")\n    }\n    ws.event.error = { error in\n        print(\"error \\(error)\")\n    }\n    ws.event.message = { message in\n        if let text = message as? String {\n            print(\"recv: \\(text)\")\n            if messageNum == 10 {\n                ws.close()\n            } else {\n                send()\n            }\n        }\n    }\n}\n```\n\n## Custom Headers\n```swift\nvar request = URLRequest(url: URL(string:\"ws://url\")!)\nrequest.addValue(\"AUTH_TOKEN\", forHTTPHeaderField: \"Authorization\")\nrequest.addValue(\"Value\", forHTTPHeaderField: \"X-Another-Header\")\nlet ws = WebSocket(request: request)\n```\n\n## Reuse and Delaying WebSocket Connections\nv2.3.0+ makes available an optional `open` method. This will allow for a `WebSocket` object to be instantiated without an immediate connection to the server. It can also be used to reconnect to a server following the `close` event.\n\nFor example,\n\n```swift\nlet ws = WebSocket()\nws.event.close = { _,_,_ in\n    ws.open()                 // reopen the socket to the previous url\n    ws.open(\"ws://otherurl\")  // or, reopen the socket to a new url\n}\nws.open(\"ws://url\") // call with url\n```\n\n## Compression\n\nThe `compression` flag may be used to request compressed messages from the server. If the server does not support or accept the request, then connection will continue as normal, but with uncompressed messages.\n\n```swift\nlet ws = WebSocket(\"ws://url\")\nws.compression.on = true\n```\n\n## Self-signed SSL Certificate\n\n```swift\nlet ws = WebSocket(\"ws://url\")\nws.allowSelfSignedSSL = true\n```\n\n## Network Services (VoIP, Video, Background, Voice)\n\n```swift\n// Allow socket to handle VoIP in the background.\nws.services = [.VoIP, .Background] \n```\n## Installation (iOS and OS X)\n\n### [Carthage]\n\n[Carthage]: https://github.com/Carthage/Carthage\n\nAdd the following to your Cartfile:\n\n```\ngithub \"tidwall/SwiftWebSocket\"\n```\n\nThen run `carthage update`.\n\nFollow the current instructions in [Carthage's README][carthage-installation]\nfor up to date installation instructions.\n\n[carthage-installation]: https://github.com/Carthage/Carthage#adding-frameworks-to-an-application\n\nThe `import SwiftWebSocket` directive is required in order to access SwiftWebSocket features.\n\n### [CocoaPods]\n\n[CocoaPods]: http://cocoapods.org\n\nAdd the following to your [Podfile](http://guides.cocoapods.org/using/the-podfile.html):\n\n```ruby\nuse_frameworks!\npod 'SwiftWebSocket'\n```\n\nThen run `pod install` with CocoaPods 0.36 or newer.\n\nThe `import SwiftWebSocket` directive is required in order to access SwiftWebSocket features.\n\n### Manually\n\nCopy the `SwiftWebSocket/WebSocket.swift` file into your project.  \nYou must also add the `libz.dylib` library. `Project -\u003e Target -\u003e Build Phases -\u003e Link Binary With Libraries`\n\nThere is no need for `import SwiftWebSocket` when manually installing.\n\n\n\n\n## Contact\nJosh Baker [@tidwall](http://twitter.com/tidwall)\n\n## License\n\nSwiftWebSocket source code is available under the MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftidwall%2FSwiftWebSocket","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftidwall%2FSwiftWebSocket","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftidwall%2FSwiftWebSocket/lists"}