Estimated reading time: 1 minute

To use this feature, you need to include io.ktor:ktor-client-websocket artifact.

Ktor provides a WebSocket client in addition to supporting WebSockets at server side.

Once connected, client and server WebSockets share the same WebSocketSession interface for communication.

Right now, client WebSockets are only available for the CIO Client Engine.

The basic usage to create a http client supporting WebSockets is pretty simple:

val client = HttpClient(CIO).config { install(WebSockets) }

Once created we can perform a request, starting a WebSocketSession:

client.ws(method = HttpMethod.Get, host = "", port = 8080, path = "/route/path/to/ws") { // this: WebSocketSession
    send(Frame.Text("Hello World"))

    for (message in incoming.map { it as? Frame.Text }.filterNotNull()) {

You can configure timeout and ping periods by casting to DefaultWebSocketSession (next version won’t require this):

client.ws(...) { // this: WebSocketSession
    (this as DefaultWebSocketSession).timeout = Duration.ofMinutes(10)
    (this as DefaultWebSocketSession).pingInterval = Duration.ofMinutes(10) // null to disable it