且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

TCP服务器端和客户端建立连接 - 客户端的回调处理

更新时间:2022-09-13 11:46:03

使用异步操作client.connect发起连接,

async function startClient(ip = configJson.TCP.client.ip, port = configJson.TCP.client.port) {
    client = new net.Socket();
    await client.connect(port, ip, () => {
      console.log(" in tcpclient.js connect callback!!! await function");
    });

TCP服务器端和客户端建立连接 - 客户端的回调处理

client.on('connect', (dataTmp) => {
        log.info('Congratulations! Statemachine is connected(in callback)');
    // send message to TCP server, method: subscribe, data: { group: "statemachine"} 
            TCPClient.sendMessage(message.message({group: "statemachine"},'subscribe'));
    })

TCP服务器端和客户端建立连接 - 客户端的回调处理