WebSocketClient

WebSocket client

WebSocketClient.swift:42
struct WebSocketClient

Connect to HTTP server with WebSocket upgrade available.

Supports TLS via both NIOSSL and Network framework.

Initialize the WebSocketClient with your handler and then call run to connect. The handler is provider with an inbound stream of WebSocket packets coming from the server and an outbound writer that can be used to write packets to the server.

let webSocket = WebSocketClient(url: "ws://test.org/ws", logger: logger) { inbound, outbound, context in
    for try await packet in inbound {
        if case .text(let string) = packet {
            try await outbound.write(.text(string))
        }
    }
}