Home > front end >  How do I set the socketTimeout in ktor?
How do I set the socketTimeout in ktor?

Time:06-27

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

CodePudding user response:

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