WebSocketServer is an S4-Compatible Responder
and Middleware
that establishes a WebSocket connection for each request.
import PackageDescription
let package = Package(
dependencies: [
.Package(url: "https://github.com/Zewo/WebSocketServer.git", majorVersion: 0, minor: 14),
]
)
In both of these examples, the HTTPServer module is used.
WebSocketServer
can be used as a responder or a middleware:
import WebSocketServer
import HTTPServer
let server = WebSocketServer { req, ws in
print("Connected!")
ws.onText { text in
print("text: \(text)")
try ws.send(text)
}
ws.onClose {(code, reason) in
print("\(code): \(reason)")
}
}
try Server(responder: server).start()
It can also be created directly from a request:
import WebSocketServer
import HTTPServer
try Server { request in
return try request.webSocket { req, ws in
print("connected")
ws.onBinary { data in
print("data: \(data)")
try ws.send(data)
}
ws.onText { text in
print("data: \(text)")
try ws.send(text)
}
}
}.start()
If you need any help you can join our Slack and go to the #help channel. Or you can create a Github issue in our main repository. When stating your issue be sure to add enough details, specify what module is causing the problem and reproduction steps.
The entire Zewo code base is licensed under MIT. By contributing to Zewo you are contributing to an open and engaged community of brilliant Swift programmers. Join us on Slack to get to know us!
This project is released under the MIT license. See LICENSE for details.