Hi everyone. I'd like to set up the connection tim...
# ktor
a
Hi everyone. I'd like to set up the connection timeout for Java and JS Websocket clients. I came up with such solution for Java client, but I'm struggling to find a way to do the same for the JS client. Does anyone have any ideas?
Copy code
HttpClient(Java) {
	install(WebSockets) { pingInterval = pingIntervalMs }
	engine {
		config {
			connectTimeout(Duration.ofSeconds(10))
		}
	}
}
a
Have you tried using the HttpTimeout plugin?
a
Hm, I tried setting an HTTP timeout with the Java client, but it didn’t have any effect. I assumed it wouldn’t work with the JS client either. But okay, I’ll try it with the JS client later today.
Unfortunately, with JS client it also doesn’t work in context of WebSockets:
Copy code
HttpClient(Js) {
    install(HttpTimeout) {
        connectTimeoutMillis = 10_000L
    }
    install(WebSockets) { pingInterval = pingIntervalMs }
}
This code also doesn’t work:
Copy code
webSocketSession = client.webSocketSession(url) {
    timeout {
        connectTimeoutMillis = 10_000L
        requestTimeoutMillis = 10_000L
        socketTimeoutMillis = 10_000L
    }
}
a
Unfortunately, the connection timeout isn't implemented for the JS engine. However, the request timeout should have an effect.
a
Ah, I can’t confirm if the request timeout will work for us since the server connection issue is already resolved and the connection establishes instantly. Still, thanks for the information!