[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-6730":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":9,"language":10,"languages":9,"totalLinesOfCode":9,"stars":11,"forks":12,"watchers":13,"openIssues":14,"contributorsCount":15,"subscribersCount":15,"size":15,"stars1d":15,"stars7d":16,"stars30d":17,"stars90d":15,"forks30d":15,"starsTrendScore":18,"compositeScore":19,"rankGlobal":9,"rankLanguage":9,"license":20,"archived":21,"fork":21,"defaultBranch":22,"hasWiki":23,"hasPages":21,"topics":24,"createdAt":9,"pushedAt":9,"updatedAt":32,"readmeContent":33,"aiSummary":34,"trendingCount":15,"starSnapshotCount":15,"syncStatus":16,"lastSyncTime":35,"discoverSource":36},6730,"Starscream","daltoniam\u002FStarscream","daltoniam","Websockets in swift for iOS and OSX",null,"Swift",8641,1263,131,146,0,2,16,1,67.91,"Apache License 2.0",false,"master",true,[25,26,27,28,29,30,31],"osx","protocol","starscream","swift","websocket","websocket-client","websockets","2026-06-12 04:00:30","![starscream](https:\u002F\u002Fraw.githubusercontent.com\u002Fdaltoniam\u002Fstarscream\u002Fassets\u002Fstarscream.jpg)\n\nStarscream is a conforming WebSocket ([RFC 6455](https:\u002F\u002Fdatatracker.ietf.org\u002Fdoc\u002Fhtml\u002Frfc6455)) library in Swift.\n\n## Features\n\n- Conforms to all of the base [Autobahn test suite](https:\u002F\u002Fcrossbar.io\u002Fautobahn\u002F).\n- Nonblocking. Everything happens in the background, thanks to GCD.\n- TLS\u002FWSS support.\n- Compression Extensions support ([RFC 7692](https:\u002F\u002Ftools.ietf.org\u002Fhtml\u002Frfc7692))\n\n### Import the framework\n\nFirst thing is to import the framework. See the Installation instructions on how to add the framework to your project.\n\n```swift\nimport Starscream\n```\n\n### Connect to the WebSocket Server\n\nOnce imported, you can open a connection to your WebSocket server. Note that `socket` is probably best as a property, so it doesn't get deallocated right after being setup.\n\n```swift\nvar request = URLRequest(url: URL(string: \"http:\u002F\u002Flocalhost:8080\")!)\nrequest.timeoutInterval = 5\nsocket = WebSocket(request: request)\nsocket.delegate = self\nsocket.connect()\n```\n\nAfter you are connected, there is either a delegate or closure you can use for process WebSocket events.\n\n### Receiving data from a WebSocket\n\n`didReceive` receives all the WebSocket events in a single easy to handle enum.\n\n```swift\nfunc didReceive(event: WebSocketEvent, client: WebSocket) {\n\tswitch event {\n\tcase .connected(let headers):\n\t\tisConnected = true\n\t\tprint(\"websocket is connected: \\(headers)\")\n\tcase .disconnected(let reason, let code):\n\t\tisConnected = false\n\t\tprint(\"websocket is disconnected: \\(reason) with code: \\(code)\")\n\tcase .text(let string):\n\t\tprint(\"Received text: \\(string)\")\n\tcase .binary(let data):\n\t\tprint(\"Received data: \\(data.count)\")\n\tcase .ping(_):\n\t\tbreak\n\tcase .pong(_):\n\t\tbreak\n\tcase .viabilityChanged(_):\n\t\tbreak\n\tcase .reconnectSuggested(_):\n\t\tbreak\n\tcase .cancelled:\n\t\tisConnected = false\n\tcase .error(let error):\n\t\tisConnected = false\n\t\thandleError(error)\n        case .peerClosed:\n               break\n\t}\n}\n```\n\nThe closure of this would be:\n\n```swift\nsocket.onEvent = { event in\n\tswitch event {\n\t\t\u002F\u002F handle events just like above...\n\t}\n}\n```\n\n### Writing to a WebSocket\n\n### write a binary frame\n\nThe writeData method gives you a simple way to send `Data` (binary) data to the server.\n\n```swift\nsocket.write(data: data) \u002F\u002Fwrite some Data over the socket!\n```\n\n### write a string frame\n\nThe writeString method is the same as writeData, but sends text\u002Fstring.\n\n```swift\nsocket.write(string: \"Hi Server!\") \u002F\u002Fexample on how to write text over the socket!\n```\n\n### write a ping frame\n\nThe writePing method is the same as write, but sends a ping control frame.\n\n```swift\nsocket.write(ping: Data()) \u002F\u002Fexample on how to write a ping control frame over the socket!\n```\n\n### write a pong frame\n\nthe writePong method is the same as writePing, but sends a pong control frame.\n\n```swift\nsocket.write(pong: Data()) \u002F\u002Fexample on how to write a pong control frame over the socket!\n```\n\nStarscream will automatically respond to incoming `ping` control frames so you do not need to manually send `pong`s.\n\nHowever if for some reason you need to control this process you can turn off the automatic `ping` response by disabling `respondToPingWithPong`.\n\n```swift\nsocket.respondToPingWithPong = false \u002F\u002FDo not automaticaly respond to incoming pings with pongs.\n```\n\nIn most cases you will not need to do this.\n\n### disconnect\n\nThe disconnect method does what you would expect and closes the socket.\n\n```swift\nsocket.disconnect()\n```\n\nThe disconnect method can also send a custom close code if desired.\n\n```swift\nsocket.disconnect(closeCode: CloseCode.normal.rawValue)\n```\n\n### Custom Headers, Protocols and Timeout\n\nYou can override the default websocket headers, add your own custom ones and set a timeout:\n\n```swift\nvar request = URLRequest(url: URL(string: \"ws:\u002F\u002Flocalhost:8080\u002F\")!)\nrequest.timeoutInterval = 5 \u002F\u002F Sets the timeout for the connection\nrequest.setValue(\"someother protocols\", forHTTPHeaderField: \"Sec-WebSocket-Protocol\")\nrequest.setValue(\"14\", forHTTPHeaderField: \"Sec-WebSocket-Version\")\nrequest.setValue(\"chat,superchat\", forHTTPHeaderField: \"Sec-WebSocket-Protocol\")\nrequest.setValue(\"Everything is Awesome!\", forHTTPHeaderField: \"My-Awesome-Header\")\nlet socket = WebSocket(request: request)\n```\n\n### SSL Pinning\n\nSSL Pinning is also supported in Starscream.\n\n\nAllow Self-signed certificates:\n\n```swift\nvar request = URLRequest(url: URL(string: \"ws:\u002F\u002Flocalhost:8080\u002F\")!)\nlet pinner = FoundationSecurity(allowSelfSigned: true) \u002F\u002F don't validate SSL certificates\nlet socket = WebSocket(request: request, certPinner: pinner)\n```\n\nTODO: Update docs on how to load certificates and public keys into an app bundle, use the builtin pinner and TrustKit.\n\n### Compression Extensions\n\nCompression Extensions ([RFC 7692](https:\u002F\u002Ftools.ietf.org\u002Fhtml\u002Frfc7692)) is supported in Starscream.  Compression is enabled by default, however compression will only be used if it is supported by the server as well. You may enable compression by adding a `compressionHandler`:\n\n```swift\nvar request = URLRequest(url: URL(string: \"ws:\u002F\u002Flocalhost:8080\u002F\")!)\nlet compression = WSCompression()\nlet socket = WebSocket(request: request, compressionHandler: compression)\n```\n\nCompression should be disabled if your application is transmitting already-compressed, random, or other uncompressable data.\n\n### Custom Queue\n\nA custom queue can be specified when delegate methods are called. By default `DispatchQueue.main` is used, thus making all delegate methods calls run on the main thread. It is important to note that all WebSocket processing is done on a background thread, only the delegate method calls are changed when modifying the queue. The actual processing is always on a background thread and will not pause your app.\n\n```swift\nsocket = WebSocket(url: URL(string: \"ws:\u002F\u002Flocalhost:8080\u002F\")!, protocols: [\"chat\",\"superchat\"])\n\u002F\u002Fcreate a custom queue\nsocket.callbackQueue = DispatchQueue(label: \"com.vluxe.starscream.myapp\")\n```\n\n## Example Project\n\nCheck out the SimpleTest project in the examples directory to see how to setup a simple connection to a WebSocket server.\n\n## Requirements\n\nStarscream works with iOS 8\u002F10.10 or above for CocoaPods\u002Fframework support. To use Starscream with a project targeting iOS 7, you must include all Swift files directly in your project.\n\n## Installation\n\n### Swift Package Manager\n\nThe [Swift Package Manager](https:\u002F\u002Fswift.org\u002Fpackage-manager\u002F) is a tool for automating the distribution of Swift code and is integrated into the `swift` compiler.\n\nOnce you have your Swift package set up, adding Starscream as a dependency is as easy as adding it to the `dependencies` value of your `Package.swift`.\n\n```swift\ndependencies: [\n    .package(url: \"https:\u002F\u002Fgithub.com\u002Fdaltoniam\u002FStarscream.git\", from: \"4.0.6\")\n]\n```\n\n### CocoaPods\n\nCheck out [Get Started](http:\u002F\u002Fcocoapods.org\u002F) tab on [cocoapods.org](http:\u002F\u002Fcocoapods.org\u002F).\n\nTo use Starscream in your project add the following 'Podfile' to your project\n\n\tsource 'https:\u002F\u002Fgithub.com\u002FCocoaPods\u002FSpecs.git'\n\tplatform :ios, '12.0'\n\tuse_frameworks!\n\n\tpod 'Starscream', '~> 4.0.6'\n\nThen run:\n\n    pod install\n\n### Carthage\n\nCheck out the [Carthage](https:\u002F\u002Fgithub.com\u002FCarthage\u002FCarthage) docs on how to add a install. The `Starscream` framework is already setup with shared schemes.\n\n[Carthage Install](https:\u002F\u002Fgithub.com\u002FCarthage\u002FCarthage#adding-frameworks-to-an-application)\n\nYou can install Carthage with [Homebrew](http:\u002F\u002Fbrew.sh\u002F) using the following command:\n\n```bash\n$ brew update\n$ brew install carthage\n```\n\nTo integrate Starscream into your Xcode project using Carthage, specify it in your `Cartfile`:\n\n```\ngithub \"daltoniam\u002FStarscream\" >= 4.0.6\n```\n\n### Other\n\nSimply grab the framework (either via git submodule or another package manager).\n\nAdd the `Starscream.xcodeproj` to your Xcode project. Once that is complete, in your \"Build Phases\" add the `Starscream.framework` to your \"Link Binary with Libraries\" phase.\n\n### Add Copy Frameworks Phase\n\nIf you are running this in an OSX app or on a physical iOS device you will need to make sure you add the `Starscream.framework` to be included in your app bundle. To do this, in Xcode, navigate to the target configuration window by clicking on the blue project icon, and selecting the application target under the \"Targets\" heading in the sidebar. In the tab bar at the top of that window, open the \"Build Phases\" panel. Expand the \"Link Binary with Libraries\" group, and add `Starscream.framework`. Click on the + button at the top left of the panel and select \"New Copy Files Phase\". Rename this new phase to \"Copy Frameworks\", set the \"Destination\" to \"Frameworks\", and add `Starscream.framework` respectively.\n\n## TODOs\n\n- [ ] Proxy support\n- [ ] Thread safe implementation\n- [ ] Better testing\u002FCI\n- [ ] SSL Pinning\u002Fclient auth examples\n\n## License\n\nStarscream is licensed under the Apache v2 License.\n\n## Contact\n\n### Dalton Cherry\n* https:\u002F\u002Fgithub.com\u002Fdaltoniam\n* http:\u002F\u002Ftwitter.com\u002Fdaltoniam\n* http:\u002F\u002Fdaltoniam.com\n\n### Austin Cherry ###\n* https:\u002F\u002Fgithub.com\u002Facmacalister\n* http:\u002F\u002Ftwitter.com\u002Facmacalister\n* http:\u002F\u002Faustincherry.me\n","Starscream是一个用于iOS和macOS的Swift编写的WebSocket库。它遵循RFC 6455标准，支持Autobahn测试套件，并通过GCD实现了非阻塞操作。此外，Starscream还支持TLS\u002FWSS加密以及压缩扩展（RFC 7692）。该库提供了丰富的API接口来处理连接、接收消息、发送数据等WebSocket通信功能，包括文本、二进制数据及控制帧（如ping\u002Fpong）的传输。适用于需要在Apple平台上实现实时双向通信的应用场景，比如在线聊天、实时游戏或任何要求即时数据交换的服务。","2026-06-11 03:08:35","top_language"]