Socket IO Server to Server

前端 未结 3 1486
时光取名叫无心
时光取名叫无心 2020-12-04 19:37

Is it possible for a server to connect to another using Socket.IO and be treated like a client?

And have it join rooms, recieve io.sockets.in(\'lobby\').emit(). And

3条回答
  •  借酒劲吻你
    2020-12-04 20:11

    Yes, absolutely. Just use the Socket.IO client in your server application directly.

    https://github.com/LearnBoost/socket.io-client

    You can install it with npm install socket.io-client. Then to use:

    var socket = io.connect('http://example.com');
    socket.on('connect', function () {
      // socket connected
      socket.emit('server custom event', { my: 'data' });
    });
    

提交回复
热议问题