Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8867403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:01:15+00:00 2026-06-14T17:01:15+00:00

I have a Node.js web server that runs a socket server on top, which

  • 0

I have a Node.js web server that runs a socket server on top, which was created using Socket.io. Basically, this works.

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 localhost:3000/A or localhost:3000/B.

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.

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.

What is the best way to design such a system using Socket.io?

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.

How should I model this? What are the right terms I should look for?

UPDATE: According to the answer of @sdedelbrock I could use namespace or rooms:

  • If use namespaces, I am not long able to send to everybody, regardless of their namespace. This is because io.sockets is a shortcut to io.of(''), which of course does not match the namespace any longer.
  • This means that I should use rooms, but I wonder what the semantic difference between a room and a namespace is.

To cut it short: Why are there two concepts for the same (?) idea?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T17:01:16+00:00Added an answer on June 14, 2026 at 5:01 pm

    You could be using rooms so you would do the following to emit to everybody in a room

    io.sockets.in('a').emit('inA', 'foo')
    

    Then to emit to everybody you can use

    io.sockets.emit('everyone','bar');
    

    You can also use namespaces as well:

    io.of('/b').emit('inB', 'buzz');
    

    To emit to everyone except the user that triggered you would use:

    io.sockets.broadcast.emit("hello");
    

    [edit] Here is a more detailed answer:

    The idea behind name-spacing is that it is handled separately from the other namespaces (even global). Think of it as if it was an entirely new socket.io instance, you can run new handshakes, fresh events, authorizations, etc without the different namespaces interfering with each other.

    This would be useful for say /chat and /tracking where the connection event would have very different logic

    Socket.io does all the work for you as if it is two separate instances, but still limits the information to one connection, which is pretty smart.

    There might be a workaround in which you can broadcast to all the namespaces (example below). However in short you shouldn’t be doing this, you should be using rooms.

    for (var nameSpace in io.sockets.manager.namespaces){
      io.of(nameSpace).emit("messageToAll", message);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working with Node.js to build a web socket server that uses mongodb.
I'm using one server to host multiple Node.js web apps, which are distributed across
I have a web page that establishes communication with a node.js server. I am
I have a Node.js web server running on an embedded Linux system. For authentication
I have a node application that is not a web application - it completes
I have two tables that look like this: node: NID Name 1 Chicago 2
I need to create multi node web server that will be allow to control
I have a need for a simple, lightweight .Net-based web server engine that will
I have started this web scraping project backwards by beginning with node.io. I have
I have a server which supports web sockets. Browsers connect to my site and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.