Sending message to a specific ID in Socket.IO 1.0

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

    If you have used a namespace I found that the following works :

    //Defining the namespace 
    var nsp = io.of('/my-namespace'); //targeting the message to socket id
    nsp.to(socket id of the intended recipient).emit('private message', 'hello');

    More about namespaces: http://socket.io/docs/rooms-and-namespaces/

提交回复
热议问题