Note that there are some explanatory texts on larger screens.

plurals
  1. POSocket.io: Namespaces, channels & co
    primarykey
    data
    text
    <p>I have a Node.js web server that runs a socket server on top, which was created using <a href="http://www.socket.io" rel="nofollow noreferrer">Socket.io</a>. Basically, this works.</p> <p>What I now want to achieve is that the clients that connect are clustered in groups. So there might be some clients which make up group A and some other clients which make up group B. They shall select to which group they belong by adressing a specific URL, either <code>localhost:3000/A</code> or <code>localhost:3000/B</code>.</p> <p>In Socket.io I now want to send messages to all clients in group A or to all clients in group B or to all clients, without looking at their group.</p> <p>It's basically like having a chat with rooms, and you have either messages for all clients within a specific room, or for any client, no matter what room he is in.</p> <p>What is the best way to design such a system using Socket.io?</p> <p>I have been trying using namespace so far, which basically works for creating groups A and B, but then I lose the ability to send messages to all clients, no matter what room they are in. At least I don't know how to do this.</p> <p>How should I model this? What are the right terms I should look for?</p> <p><strong>UPDATE:</strong> According to the answer of <a href="https://stackoverflow.com/users/1174481/sdedelbrock">@sdedelbrock</a> I could use namespace or rooms:</p> <ul> <li>If use namespaces, I am not long able to send to everybody, regardless of their namespace. This is because <code>io.sockets</code> is a shortcut to <code>io.of('')</code>, which of course does not match the namespace any longer.</li> <li>This means that I should use rooms, but I wonder what the semantic difference between a room and a namespace is.</li> </ul> <p>To cut it short: Why are there two concepts for the same (?) idea?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload