@Override
    protected NioChannel doConnect(SocketAddress remoteAddress, NioSelectorLoop selectorLoop, Futures.ConnectFuture connectFuture) {

        SocketChannel socketChannel = newSocket();
        try {
            socketChannel.socket().setSoTimeout(clientConfig.getConnectTimeout());

            socketChannel.configureBlocking(false);

            if (clientConfig.getTcpNoDelay() != null) {
                socketChannel.socket().setTcpNoDelay(clientConfig.getTcpNoDelay());
            }
            if (clientConfig.getReceiveBufferSize() != null) {
                socketChannel.socket().setReceiveBufferSize(clientConfig.getReceiveBufferSize());
            }
            if (clientConfig.getKeepAlive() != null) {
                socketChannel.socket().setKeepAlive(clientConfig.getKeepAlive());
            }
            if (clientConfig.getReuseAddress() != null) {
                socketChannel.socket().setReuseAddress(clientConfig.getReuseAddress());
            }
            if (clientConfig.getIpTos() != null) {
                socketChannel.socket().setTrafficClass(clientConfig.getIpTos());
            }
            if (clientConfig.getOobInline() != null) {
                socketChannel.socket().setOOBInline(clientConfig.getOobInline());
            }
            if (clientConfig.getSoLinger() != null) {
                socketChannel.socket().setSoLinger(true, clientConfig.getSoLinger());
            }

        } catch (IOException e) {
            throw new NioException("connect IOE", e);
        }

        this.channel = new NioChannelImpl(selectorLoop, this, socketChannel, eventHandler(), clientConfig);

        try {
            socketChannel.connect(remoteAddress);
            socketChannel.register(this.selectorLoop.selector(), SelectionKey.OP_CONNECT);
        } catch (IOException e) {
            connectFuture.setCause(e);
            connectFuture.setSuccess(false);
            connectFuture.notifyListeners();
            this.channel = null;
            return null;
        }

        channelInitializer.initChannel(this.channel);
        idleDetector.addChannel(channel);
        connectFuture.setSuccess(true);
        connectFuture.setChannel(channel);
        connectFuture.notifyListeners();
        return channel;
    }
@author Robert HG (254963746@qq.com) on 2/2/16.
lts-core/src/main/java/com/github/ltsopensource/nio/processor/NioClientProcessor.java