public boolean connect(boolean needPrint, long termId) {
        // Initial status
        this.conStatus.set(CLIENT_STATUS_INIT);
        long curTime = System.currentTimeMillis();
        final CountDownLatch awaitLatch = new CountDownLatch(1);
        // Build connect to server
        ChannelFuture future = bootstrap.connect(
                new InetSocketAddress(hostInfo.getHostName(), hostInfo.getPortNumber()));
        future.addListener(new ChannelFutureListener() {

            public void operationComplete(ChannelFuture arg0) throws Exception {
                awaitLatch.countDown();
            }
        });
        try {
            // Wait until the connection is built.
            awaitLatch.await(tcpConfig.getConnectTimeoutMs(), TimeUnit.MILLISECONDS);
        } catch (Throwable ex) {
            if (conExptCnt.shouldPrint()) {
                logger.warn("NettyClient({}) connect to {} exception",
                        senderId, hostInfo.getReferenceName(), ex);
            }
            return false;
        }
        // Return if no connection is built.
        if (!future.isSuccess()) {
            this.conFailCnt.getAndIncrement();
            this.lstConFailTime.set(System.currentTimeMillis());
            if (conExptCnt.shouldPrint()) {
                logger.warn("NettyClient({}) connect to {} failure, wast {}ms",
                        senderId, hostInfo.getReferenceName(), (System.currentTimeMillis() - curTime));
            }
            return false;
        }
        this.channelTermId.set(termId);
        this.channel = future.channel();
        this.channelStr = this.channel.toString();
        this.conFailCnt.set(0);
        this.msgSentCnt.set(0);
        this.chanSyncTimeoutCnt.set(0);
        this.msgInflightCnt.set(0);
        this.conStatus.set(CLIENT_STATUS_READY);
        if (needPrint) {
            logger.info("NettyClient({}) connect to {} success, wast {}ms",
                    senderId, channel.toString(), (System.currentTimeMillis() - curTime));
        }
        return true;
    }
TCP Netty client class

Used to manage TCP netty client, including connection, closing, keep-alive, sending status check, etc.
inlong-sdk/dataproxy-sdk/src/main/java/org/apache/inlong/sdk/dataproxy/network/tcp/TcpNettyClient.java