I\'m trying to connect to a remote server and send a login message in my Thread:
@Override
public void run() {
try {
address = new InetSocketAddr
If you're connecting in non-blocking mode you should:
OP_CONNECT
finishConnect()
OP_CONNECT
and register OP_READ
or OP_WRITE
depending on what you want to do nextconnect()
or finishConnect()
throws an exception, close the channel and try again or forget about it or tell the user or whatever is appropriate.If you don't want to do anything until the channel connects, do the connect in blocking mode and go into non-blocking mode when the connect succeeds.
i've found an answer.. i should use:
socketChannel = SocketChannel.open(address);
socketChannel.configureBlocking(false);
while (!socketChannel.finishConnect());
//my code after connection
because the NIO is in not blocking mode we have to wait until it finish its connection