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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:14:20+00:00 2026-05-27T06:14:20+00:00

Here are 2 related questions. Posting them together makes more sense. Question 1 I

  • 0

Here are 2 related questions. Posting them together makes more sense.

Question 1

I have a node.js app which emits an event out to all clients, and all current clients will respond with a ready emit. How can I create a list of all the clients that replied to the initial emit, and what kind of identification can be used to distinguish the clients?

Question2:

What I am trying to do after collect a list of connected clients, is to then access a MySQL database table of N number of rows and assign each client X rows each. These rows will be emitted back to their respective clients. How can this be done?

Current Code for Qn 1

Node Code

setInterval(function() {
    util.log('Checking for new jobs...');
    dbCheckQueue(function(results) {  // checks if there are new rows to "distribute" to clients
        if (results.length) {
            util.log(results.length + ' new jobs found.');
            io.sockets.emit('job_available');
        }
    });
}, 10*1000);

Client-side JS Code

socket.on('job_available', function() {
                console.log('Job Available.. Responding with Ready!');
                socket.emit('ready');
            });

io.sockets.on('connection', function(socket) {
    socket.on('ready', function() {
        // UPDATE N rows with client_id in column checkout.
        // Then SELECTS * from table where checkout = client_id
        getListings(client_id, function(listings) {
            socket.emit('job', listings);   // send jobs
        });
    });
});

Current Code for Qn 2
The code works for a single client, but how do I loop through all connected clients and perform the same updating of column and selecting of rows?

io.sockets.on('connection', function(socket) {
    socket.on('ready', function() {
        // UPDATE N rows with client_id in column checkout.
        // Then SELECTS * from table where checkout = client_id
        getListings(client_id, function(listings) {
            socket.emit('job', listings);   // send jobs
        });
    });
});
  • 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-27T06:14:20+00:00Added an answer on May 27, 2026 at 6:14 am

    You will need to keep track of the connected clients yourself. The simple way to do that would be to use an array:

    var clients = [];
    
    io.sockets.on('connect', function(client) {
        clients.push(client); 
    
        client.on('disconnect', function() {
            clients.splice(clients.indexOf(client), 1);
        });
    });
    

    Then you can references that clients array on the server wherever you need to, in your ready event handler or whatever. Something like:

    io.sockets.on('connection', function(socket) {
        socket.on('ready', function() {
            // UPDATE N rows with client_id in column checkout.
            // Then SELECTS * from table where checkout = client_id
            clients.forEach(function(client, index) {
                var client_id = index; // Just use the index in the clients array for now
                getListings(client_id, function(listings) {
                    socket.emit('job', listings);   // send jobs
                });
            });
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have tried solving this problem by posting other related questions here that focused
i found many related questions here. I have a simple java program . it
I have seen other questions on here related to this, but I have their
I have seen the related question here: An object with the same key already
I have tried to find the related questions here. I think it is a
Kind of similar to how the Related Questions search works here when posting questions:
I have seen some of the questions/answers related to this topic here, however still
I often see people asking XML/XSLT related questions here that root in the inability
I've looked at several other SGen-related questions on here and either their answers don't
I read a number of of jquery ui button related questions on here, 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.