how to show the socket id in 'connection' callback

92 Views Asked by At

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);
  });
});
1

There are 1 best solutions below

0
On

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