https://kotlinlang.org logo
#ktor
Title
# ktor
a

Arthur Krukowski

03/06/2023, 3:17 PM
And one more question about Ktor on
JS
platform: Is there a way how to configure ping interval using Websockets?? Looks like the
pingInterval
field doesn't have any effect. Moreover, when you try to access
pingIntervalMillis
field it throws an exception that it is not supported. Is there a workaround/approach for tracking connection lost using websockets in browser?
Copy code
val socket: HttpClient = HttpClient { install(WebSockets) { pingInterval = 10_000 }}
var webSocketSession: DefaultClientWebSocketSession = socket.webSocketSession("your-ws-url")

try {
   println("ping interval: ${webSocketSession.pingIntervalMillis}")
} catch (e: Throwable) {
    println("ex $e")  // ex WebSocketException: Websocket ping-pong is not supported in JS engine.
}
If after subscribing on some channel you turn off the internet connection, the WS client just endlessly waits, and only after the restoring connection, it spits out all remaining messages from the buffer (as I understand it) and then close connection by sending Frame.Close message (without throwing any timeout exceptions)
4 Views