Client WebSockets
Once connected, client and server WebSockets share the same WebSocketSession interface for communication.
Once created we can perform a request, starting a :
client.ws(
method = HttpMethod.Get,
host = "127.0.0.1",
port = 8080, path = "/route/path/to/ws"
) { // this: DefaultClientWebSocketSession
send("Hello, Text frame")
// Send text frame.
send(Frame.Text("Hello World"))
// Send binary frame.
// Receive frame.
val frame = incoming.receive()
when (frame) {
is Frame.Text -> println(frame.readText())
is Frame.Binary -> println(frame.readBytes())
}