Closed
Description
Hi,
One of the constructors of WebSocketClient takes a value for a timeout, but it is actually never used. The default timeout used by SocketChannel.connect() seems to be something around two minutes if the remote host does not answer. For my use case much shorter timeouts are necessary. I fixed it for me using a thread and calling SocketChannel.close():
// method interruptibleRun():
/*
* Timeout for the SocketChannel using InterruptibleChannel.close()
* SocketChannel.connect(...) throws AsynchronousCloseException after calling close()
*/
if(timeout != 0) {
new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(timeout);
if(!channel.isConnected()) {
channel.close();
}
} catch (Exception e) {
// does not matter
}
}
}).start();
}
channel.connect( new InetSocketAddress( host, port ) );
Regards
Stefan