Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Target specific socket connections? #30

Closed
peteruithoven opened this issue Oct 1, 2014 · 7 comments
Closed

Target specific socket connections? #30

peteruithoven opened this issue Oct 1, 2014 · 7 comments

Comments

@peteruithoven
Copy link

Is there any way to target specific socket connections, from an instance that doesn't have the connection to that socket connection?
I'm afraid this requires similar functionality as rooms, which also isn't implemented yet.

@objectiveSee
Copy link
Contributor

If you need to emit events to socket.io instances from a non-socket.io process, you should use socket.io-emitter.

@peteruithoven
Copy link
Author

Thanks I'll have a look at that, maybe there is a workaround there.
But I'm actually in the situation where I use a clustered socket.io server. Now I would like to forward a message from one client (that's for example on instance A) to a specific other client (that's for example on instance B). So all instances are socket.io servers.

@shantanuthatte
Copy link

Use rooms, and send the message to the room with the client you desire.
Every client gets its own room with a unique id. So, sending it just to the
room with the id would work.

Regards,
Shantanu Thatte
On Oct 1, 2014 4:24 PM, "Peter Uithoven" notifications@github.com wrote:

Thanks I'll have a look at that, maybe there is a workaround there.
But I'm actually in the situation where I use a clustered socket.io
server. Now I would like to forward a message from one client (that's for
example on instance A) to a specific other client (that's for example on
instance B). So all instances are socket.io servers.


Reply to this email directly or view it on GitHub
#30 (comment)
.

@peteruithoven
Copy link
Author

I'll try.
I'm sorry I forgot to mention that I would like to use acknowledgment callbacks. I tried putting the target client into a room with a custom name (so I don't have to store the socket.io id in a database), but then it becomes a broadcast (to possible multiple clients) and then I can't specify a acknowledgment callback. So I tried retrieving the clients from a room, so I could target them specifically, but retrieving the clients from rooms isn't possible yet (#13).

@peteruithoven
Copy link
Author

I just want to confirm that talking to a client of another socket.io server can be done by using their socket.io id as room name. It also works when you put this target client in a custom room with a fixed name and talk to that room from another socket.io server instance.
This means that socket.io-redis does support rooms, it just can't list the clients in rooms. It probably can't list the rooms that exist in other servers either.

But sadly, emitting into a room is considered broadcasting, probably because there can be multiple clients in a room, so you can't use callbacks. You'll get the following error when trying:

Callbacks are not supported when broadcasting

@peteruithoven
Copy link
Author

So I see two possible solutions:

@peteruithoven
Copy link
Author

I created a redis pub/sub wrapper with a callback system. This allows me to, from one instance, execute a emit on another instance and retrieve the response using a callback.
https://www.npmjs.org/package/redis-pubsubber

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants