socket.io - broadcast to certain users
There are two possibilites :
1) Each socket has its own unique ID stored in socket.id
. If you know the ID of both users, then you can simply use
io.sockets[id].emit(...)
2) Define your own ID (for example user's name) and use
socket.join('priv/John');
in connection
handler. Now whenever you want send message only to John
, you simply do
socket.broadcast.to('priv/John').emit(...)
Side note: the first solution provided cannot be scaled to multiple machines, so I advice using the second one.