[英]Java - SocketChannel connection timeout
I have a problem while the socket when it find a no route to host. 我在套接字找不到主机路由时遇到了问题。 It wait for quite a long. 它等待了很长时间。 I want to change the connection timeout. 我想更改连接超时。 The select(timeout)
method of selector it's useless here. select(timeout)
器的select(timeout)
方法在这里没有用。 So i wanted to use channel.connect(address,timeout)
as socket accept, but in API there is no such method. 所以我想使用channel.connect(address,timeout)
作为套接字接受,但是在API中没有这样的方法。 So i call the method from socket like: channel.socket().connect(address, timeout)
but i get the following exception: java.nio.channels.IllegalBlockingModeException
. 所以我从套接字调用该方法,例如: channel.socket().connect(address, timeout)
但我收到以下异常: java.nio.channels.IllegalBlockingModeException
。
How do i put timeout on connection in channels? 如何在通道连接中设置超时?
You can try : 你可以试试 :
while (! channel.finishConnect()) {
<... timer like Thread.sleep() ..>
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.