WebSocketServer is an S4-CompatibleResponder and Middleware that establishes a WebSocket connection for each request.
import PackageDescription
letpackage=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
letserver=WebSocketServer{ req, ws inprint("Connected!")
ws.onText{ text inprint("text: \(text)")try ws.send(text)}
ws.onClose{(code, reason)inprint("\(code): \(reason)")}}tryServer(responder: server).start()It can also be created directly from a request:
import WebSocketServer
import HTTPServer
tryServer{ request inreturntry request.webSocket{ req, ws inprint("connected")
ws.onBinary{ data inprint("data: \(data)")try ws.send(data)}
ws.onText{ text inprint("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.
