0

I tried to use official demo in socket.io. In this demo, it gives two arguments for connection callback.first is id,second is msg.but actually in function(id, msg), i tried and find out that the id is still the message,not id actually. why?

io.on('connection', function(socket){
  socket.on('say to someone', function(id, msg){
    socket.broadcast.to(id).emit('my message', msg);
  });
});
Sunny Sun
  • 65
  • 5
  • 13

1 Answers1

0

I figured out the problem myself. if we use to(<socketid>), this cannot go to socket itself. have to go to other sockets.

Sunny Sun
  • 65
  • 5
  • 13