Answer the question
In order to leave comments, you need to log in
How to find out the recipient id when sending via socket.broadcast?
How to find out/get/specify the client id when sending him a message using the socket.broadcast method?
An example of code in which the server forwards an incoming message to other clients.
socket.on('set_data', function (data) { // обработчик входящего сообщения
socket.broadcast.emit('set_data', {
from: socket.id, // от этого клиента пришло сообщение
to: ?, // этому клиенту пересылаем сообщение
data: data
});
});
Answer the question
In order to leave comments, you need to log in
Well, as I understand it, this does not fit into the logic of socket.broadcast
broadcast means sending a message to ALL. If I need to send to a specific socket, I write this: io.sockets.socket("required socket.id here").json.send(data); I work with json for this. In your case, I think it will be like this: io.sockets.socket("required socket.id here").emit(...)
UPD: I just saw your UPD =) Why not send users their id when they first connect?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question