How do I set the socketTimeout in ktor?

Viewed 46

I tried

val socket = aSocket(ActorSelectorManager(Dispatchers.IO)).tcp().configure { 
 socketTimeout = 1000 
}.connect("127.0.0.1", 2323)

I can set other values like this but not the timeout. It's listed here TCPClientSocketOptions

1 Answers

The socketTimeout property is an extension of TCPClientSocketOptions as you said, but the scope from configure provides only SocketOptions. In order to correctly configure the TCP socket, you can specify the socketTimeout property when calling the connect function, like so:

val socket = aSocket(ActorSelectorManager(Dispatchers.IO))
            .tcp()
            .connect("127.0.0.1", 2323) {
                socketTimeout = 1000
            }
Related