Adds support for upgrading HTTP connections to WebSocket.
let app = HBApplication()
// add HTTP to WebSocket upgrade
app.ws.addUpgrade()
// add middleware to websocket initial requests
app.ws.add(middleware: HBLogRequestsMiddleware(.info))
// on websocket connect.
app.ws.on("/ws") { req, ws in
// send ping and wait for pong and repeat every 60 seconds
ws.initiateAutoPing(interval: .seconds(60))
// on read from client send the same data back
ws.onRead { data, ws in
ws.write(data)
}
}
app.start()
app.wait()
You can find reference documentation for HummingbirdWebSocket here. The hummingbird-examples repository has a number of examples of different uses of the library.
link |
Stars: 14 |
Last commit: 1 week ago |
HBChannelInitializer.addProtocolUpgrade
InitiateAutoPing
schedules the first ping instead of sending it immediatelyHBWebSocketClient
sets up HTTPDecoder
with leftOverBytesStrategy
to .forwardBytes
to ensure any remaining data in channel is passed onto websocket channel handler.Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics