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 8915491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:59:08+00:00 2026-06-15T04:59:08+00:00

Below is my code for dealing with dynamically assigned namespaces. The client connects, then,

  • 0

Below is my code for dealing with dynamically assigned namespaces. The client connects, then, using it’s referrer, the client’s account ID is looked up, and in a function not present below, if that account ID does not already have a namespace assigned to it, a new namespace is generated (UUID) or the existing namespace is returned.

Then, that namespace is emitted to the client, which responds in turn with a new connect message on that particular namespace.

This all works.

Unfortunately, the ns_socket.emit('hi'); statement gets fired back to the ns_socket for however many clients have connected.

To be clear, if client 1 connects to the namespace, the hi is fired once to that client. When client 2 connects to the same namespace, hi is fired twice to that second client for an unknown (to me) reason, when it should only fire once.

Any help would, obviously, be very much appreciated.

var main = io.of('').on('connection', function(socket) {
    socket.on('joinDynNs',function(data) {
        var nameslug = socket.handshake.headers.referer.match(/(http(s)?:\/\/)([A-Za-z0-9-]+)\./)[3];
        getActID(nameslug, function(actID) {
            var ns = getNamespace(nS, actID);
            socket.emit('assignNamespace',{ns:ns});
            io.of('/' + ns).on('connection', function(ns_socket) {
                ns_socket.emit('hi');
            });
        });
    });
});
  • 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-15T04:59:08+00:00Added an answer on June 15, 2026 at 4:59 am

    Your logic is written such that a connection handler for the namespace is created whenever a socket connects to the base namespace. Thus, every time a new client connects to the base namespace, you set up another connection handler. Put another way, you’re calling

    io.of('/' + ns).on('connection', function(ns_socket) {
        ns_socket.emit('hi');
    });
    

    every time a new connection comes in. The connection handler is not specific to the socket you’re dealing with; it fires for any new connection on the namespace. This is why you’re seeing the incrementing message counts.

    I’m not sure about your needs in full, but I would think that rooms would be a better solution for you; namespaces are really designed to be used for multiplexing connections (for example, multiple completely unrelated apps running on the same Socket.IO port); rooms allow you to group sockets into logical groups, and send messages to the sockets in that group.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Below code not work, but it's work fine for jsf1.2. Now the framework is
Below code makes form to be submitted without html5 validation... $j(document).on(click, #client_entry_add, function(event){ ajax_submit();});
The below code doesn't it print the value. function go(x) { alert(x.options.selectedIndex.value); //location=document.menu.student.options[document.menu.student.selectedIndex].value }
I found in some legacy code I'm dealing with this function (in C++) Vec3d
Below code is dealing with a TYPE* const pointer. struct D { void Check
I'm using the below function to redirect a person after specific task (eg.: after
Below code saying error incorreect syntax near Main INSERT INTO tbl ( 'Week', Main,
below code is my databasehandler class i got it from a tutorial. Beside that
Below code : URL oracle = new URL(http://www.oracle.com/); URLConnection inputStream =oracle.openConnection(); InputStream in =
In below code when I click 'Vote' a vote results screen is displayed but

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.