Node.js - io.sockets.in(room) not working

随声附和 提交于 2019-12-23 04:44:17

问题


client.on('msg', function(msg){
    //io.sockets.in(msg.room).emit('msg', msg);
    client.get('room', function(err, room) {
          io.sockets.in(room).emit('msg',msg);
    })
});

is sending the message to ALL rooms and not just 'room' but I dont userstand why. I am using

client.set("room",name,function(){ return true; });

I am setting the value on('join'), I dont see how its even an option to send to all rooms when using in() surely if it finds nothing it defaults to not sending to any, not sending to ALL?

My full server.js code

Thanks in advance guys.


回答1:


io.sockets.on("connection",function(socket){
   socket.on("load Ex",function(data){
      io.sockets.in(parseInt(data.coneference)).emit('ex mesajlar', allData);
   });
});

At your client side, you have to trigger load Ex via button click or document Ready event then create a listener socket.on in client side.

socket.on("ex mesajlar",function(data) {
    alert(data.msg);
});


来源:https://stackoverflow.com/questions/19069885/node-js-io-sockets-inroom-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!