node-websocket-server: possible to have multiple, separate “broadcasts” for a single node.js process?

前端 未结 4 1225
野趣味
野趣味 2020-11-30 16:40

I\'d like to know if it\'s possible to broadcast on different websocket \"connections\" running from the same node-websocket-server app instance. Imagine a chatroom server w

4条回答
  •  悲哀的现实
    2020-11-30 17:15

    I'm not sure if rooms were a feature when the other answers were created, but in the documentation, they have a feature exactly what you are looking for. So go to that link and search for rooms.

    Here is an example from the site:

    var io = require('socket.io').listen(80);
    
    io.sockets.on('connection', function (socket) {
      socket.join('justin bieber fans');
      socket.broadcast.to('justin bieber fans').emit('new fan');
      io.sockets.in('rammstein fans').emit('new non-fan');
    });
    

    Based on the other answers, it was more focused on scaling, I would love some insight if the built in version scales well as the proposed answers.

提交回复
热议问题