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

  • SEARCH
  • Home
  • 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 6975647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:23:42+00:00 2026-05-27T17:23:42+00:00

I’m running Socket.io multi-threaded with the native cluster functionality provided by Node.js v0.6.0 and

  • 0

I’m running Socket.io multi-threaded with the native cluster functionality provided by Node.js v0.6.0 and later (with RedisStore).

For every new change in state, the server iterates over each connection and sends a message if appropriate. Note: this isn’t “broadcasting” to all connections, it’s comparing server data with data the client sent on connection to decide whether to send the server data to that particular client. Consider this code sample:

io.sockets.clients().forEach(function (socket) {
  socket.get('subscription', function (err, message) {
   if(message.someProperty === someServerData) {
     socket.emit('position', someServerData);
   }
});

This worked fine when there was only one process, but now, the client receives a message for each Node process (ie. if there are 8 Node process running, all clients receive the messages 8 times).

I understand why the issue arises, but I’m not sure of a fix. How can I assign a 1-to-1 relation from one process to only on client. Perhaps something using NODE_WORKER_ID of Cluster?

This previous SO question seems somewhat related, although I’m not sure it’s helpful.

This seems like a pretty common request. Surely, I must be missing something?

  • 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-05-27T17:23:43+00:00Added an answer on May 27, 2026 at 5:23 pm

    So if I get this straight you need to emit custom events from the server. You can do that by creating your own custom EventEmitter and triggering events on that emitter, for example:

    var io = require('socket.io').listen(80);
        events = require('events'),
        customEventEmitter = new events.EventEmitter();
    
    
    io.sockets.on('connection', function (socket) {
      // here you handle what happens on the 'positionUpdate' event
      // which will be triggered by the server later on
      eventEmitter.on('positionUpdate', function (data) {
        // here you have a function that checks if a condition between 
        // the socket connected and your data set as a param is met
        if (condition(data,socket)) {
          // send a message to each connected socket
          // if the condition is met
          socket.emit('the new position is...');
        }
      });
    });
    
    // sometime in the future the server will emit one or more positionUpdate events
    customEventEmitter.emit('positionUpdate', data);
    

    Another solution would be to have those users join the ‘AWE150’, so only they will receive updates for ‘AWE150’, like so:

    var io = require('socket.io').listen(80);
    
    io.sockets.on('connection', function (socket) {
      if (client_is_interested_in_AWE) { socket.join('AWE150'); }
      io.sockets.in('AWE150').emit('new position here');
    });
    

    Resources:

    http://spiritconsulting.com.ar/fedex/2010/11/events-with-jquery-nodejs-and-socket-io/

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am currently running into a problem where an element is coming back from
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string

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.