Greetings, how could I make a message only reach a specific user, because using io.sockets.emit makes the message reach everyone but I could not make it reach only a user that selects, if They could guide me, I'd appreciate it.
Greetings, how could I make a message only reach a specific user, because using io.sockets.emit makes the message reach everyone but I could not make it reach only a user that selects, if They could guide me, I'd appreciate it.
you can do it in the following way:
io.to(socketid).emit('message', 'Este mensaje es único para un usuario');
The socketid
is the identifier of each of the clients connected to your server (Keep in mind that the same user can open 3 browser windows, and this would be 3 different clients).
You can, for example, create an array of socketid's and even relate the socketid of the connection with that of a logged user of your application if necessary. In this way you could distinguish it and know who it is at any time.
I hope it helps you!