im trying to implement a client app with an asynchronous connection. i want to know if i can reuse a SocketChannel
object after it has failed to connect to a server.
SocketChannel channel = SocketChannel.open();
channel.configureBlocking(false);
InetSocketAddress addr = new InetSocketAddress(host, port);
SelectionKey key = channel.register(select, SelectionKey.OP_READ, connection);
channel.connect(addr);
after this is the select loop, my socket eventually gets selected because the connection failed. i would like to queue another connection attempt on that channel, and nothing i do seems to do it. the channel.isConnectionPending()
method always returns true (even if i try to finishConnect)
is the only solution do get rid of this SocketChannel
and create a new one?