Using WebSocketKit outside of Vapor examples/documentation

At Overview - Vapor Docs it suggests that WebSocketKit can be used independently of vapor. However the example is using an HTTPClient object to start a websocket. But HTTPClient is not part of the the dependencies of WebSocketKit when using standalone. Are there any examples to share on how to get websocketkit up and running independently of Vapor?

I'm trying to create a Swift MQTT library on Linux (all the available libraries I've found either include some ObjC or use Apple network calls that are not present on linux) so piecing together things to get Swift+MQTT+Linux has proven to be a challenge.

TIA

let socket:WebSocket    = await .connect(to: url, on: group) 
            
socket.pingInterval     = .seconds(1)
socket.onText 
{ 
    (socket:WebSocket, string:String) in
}
            
try? await socket.onClose.get()

Ah, thanks. I was using WebSocketClient in the library. Tho, await is a 5.5 construct, no? LinuxARM is supported to 5.4 only thus far.

1 Like

The tests are the best place to look - e.g. https://github.com/vapor/websocket-kit/blob/main/Tests/WebSocketKitTests/WebSocketKitTests.swift#L22

And async/await can be used on Linux, (arguably) easier than it can on macOS. Just download the 5.5 preview toolchain with it in or change your Docker container to point to a nightly

Terms of Service

Privacy Policy

Cookie Policy