SocketChannel socketChannel = selector.provider().openSocketChannel();
Socket socket = socketChannel.socket();
socket.setTcpNoDelay(true);
socket.setTrafficClass(IPTOS_LOWDELAY);
socket.connect(remoteAddress, timeout); // Connect using blocking mode for simplicity.
socketChannel.configureBlocking(false);
this.socketChannel = socketChannel;
selectionKey = socketChannel.register(selector, SelectionKey.OP_READ);
selectionKey.attach(this);