socket.io icon indicating copy to clipboard operation
socket.io copied to clipboard

Is there an alternate way that I can send messages to a specific client?

Open viziionary opened this issue 10 years ago • 2 comments

Im working on a simple session based app shared by a session code in the URL. I decided to generate and assign a shorter user friendly unique ID for each client who connects to a socket, and the client who creates a session causes a socket.io room to be created with his ID.

I didnt realize until later that the private messaging mechanism in socket.io relied on each client being assigned to a room named by their ID. This means that because my room for a session is named after the creator's socket ID, using .to() will not message that client, but rather all of the clients now assigned to that room.

I could remedy this in ways that would require some re-design, but first I wanted to ask if there is an alternate way of sending a message to a specific client via his/her ID.

viziionary avatar Mar 25 '16 07:03 viziionary

This means that because my room for a session is named after the creator's socket ID, using .to() will not message that client, but rather all of the clients now assigned to that room. I don't get why.

Unfortunately, there is no alternate way but you can assign your own room for the private message, rather than using socket id.

nkzawa avatar Apr 11 '16 19:04 nkzawa

That issue was closed automatically. Please check if your issue is fixed with the latest release, and reopen if needed (with a fiddle reproducing the issue if possible).

darrachequesne avatar Jan 12 '17 16:01 darrachequesne