SwiftAsyncWebsocket is a websocket library full implement by swift.
- websocket connect and send or read data
- Fragmentation data receive
- websocket based on TLS/SSL (wss)
- child protocol extension
- Fragmentation data send
SwiftAsyncWebsocket can be easy install by following steps
git clone https://github.com/chouheiwa/SwiftAsyncWebsocket.git
cd SwiftAsyncWebsocket
pod install
open ./SwiftAsyncWebsocket.xcworkspace
And then build the project and drag the framework to your project
Add following commands to your podfile
pod 'SwiftAsyncWebsocket'
And then run pod install
SwiftAsyncWebsocket is Carthage compatible. To include it add the following line to your Cartfile
github "chouheiwa/SwiftAsyncWebsocket"
- Create request and connect
guard let url = URL(string: "ws://demos.kaazing.com/echo") else {
return
}
let request = URLRequest(url: url)
do {
let header = try RequestHeader(request: request)
let websocket = SwiftAsyncWebsocket(requestHeader: header, delegate: self, delegateQueue: DispatchQueue.main)
try websocket.connect()
} catch let error as WebsocketError {
print("\(error)")
} catch {
fatalError()
}
In real project, you need to control websocket lifecycle by yourself. And you need to implement the websocket delegate method.
There has been a demo for simple use SwiftAsyncWebsocket
Demo page: https://github.com/SwiftAsyncSocket/SwiftAsyncWebsocketDemo