Create WebSockets between a TCP server and HTTP server in node.js

后端 未结 3 1147
一个人的身影
一个人的身影 2021-02-03 14:20

I have created a TCP server using Node.js which listens to clients connections. I need to transmit data from TCP server

3条回答
  •  难免孤独
    2021-02-03 14:39

    You can use either socket.io or ws (only WebSocket) on Node.js as client (not only in browser)

    var io = require('socket.io-client');
    var socket = io.connect('http://IP address of Websocket server');
    socket.on('news', function (data) {
      console.log(data);
      socket.emit('my other event', { my: 'data' });
    });
    

提交回复
热议问题