Sending message to a specific ID in Socket.IO 1.0

后端 未结 6 963
天命终不由人
天命终不由人 2020-11-30 18:01

I want to sent data to one specific socket ID.

We used to be able to do this in the older versions:

io.sockets.socket(socketid).emit(\'message\', \'         


        
6条回答
  •  温柔的废话
    2020-11-30 18:22

    in Node.js --> socket.io --> there is a chat example to download Paste this in line (io on connection) part.. i use this code that works 100%

    io.on('connection', function(socket){
      socket.on('chat message', function(msg){
        console.log(socket.id);
        io.to(socket.id).emit('chat message', msg+' you ID is:'+socket.id);
      });
    });
    

提交回复
热议问题