问题
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