Sending message to a specific ID in Socket.IO 1.0

后端 未结 6 970
天命终不由人
天命终不由人 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:26

    @Mustafa Dokumacı and @Curious already provided enough information, I am adding how you can get socket id.

    To get socket id use socket.id:

    var chat = io.of("/socket").on('connection',onSocketConnected);
    
    function onSocketConnected(socket){
       console.log("connected :"+socket.id);  
    }
    

提交回复
热议问题