trinopoty / socket.io-server-java

Socket.IO Server Library for Java
Other
183 stars 50 forks source link

Is it possible to send messages from one namespace to a different namespace? #44

Open Ramanth opened 1 year ago

Ramanth commented 1 year ago

currently we are building socket.io server and trying to design an asyncapi spec with two channels /errors and /updates. The idea is that client will get regular updates on /updates channel and any errors or warnings in a different /errors channel.

The source of errors could be originating from logic on /updates namespace and we are trying to see if its possible to emit a message into /errors namespace from the logic thats inside the .on listner of /updates namespace?

also we observed the socket id is different when we try to connect as a client to both /updates and /errors channels. are we in the right direction or doing something basically wrong here?

Is it possible to have same socketid or socket for two different namespaces?

Assumption:

  1. we are assuming the channels on asyncapi spec to be analogous to namespace in socket.io

@trinopoty

trinopoty commented 1 year ago

Hi, If I understand your requirement correctly, you can add the socket to a room based on some identification data. When you want to send a message to the client, you can then broadcast to the room in your namespace.

I will expose some extra stuff to make use cases like this easier in future updates.