Specify connection timeout in java.nio

Posted by miorel on Stack Overflow See other posts from Stack Overflow or by miorel
Published on 2010-04-01T21:53:01Z Indexed on 2010/04/01 22:33 UTC
Read the original article Hit count: 408

Filed under:
|
|
|

Using non-blocking I/O, the code for connecting to a remote address looks something like:

SocketChannel channel = SelectorProvider.provider().openSocketChannel();
channel.configureBlocking(false);
channel.connect(address);

The connection process will then have to be finished by invoking finishConnect() on the channel when some selector says the corresponding key isConnectable().

Is there a way to specify the connection timeout when using this idiom?

© Stack Overflow or respective owner

Related posts about java

Related posts about nio