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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:05:43+00:00 2026-05-27T04:05:43+00:00

I have a loop that querys a database continuously. When the query returns a

  • 0

I have a loop that querys a database continuously. When the query returns a result, the node.js app will send a message to every client connected to the node server via socket.io v0.8.

Problem: io.sockets.broadcast.send('msg') is called in the middle of a setInterval() loop so it is not within an io.sockets.on()‘s callback function and thus this will not work. When io.sockets.send('msg') is used, no message seems to be sent to the client.

Node.js code

setInterval(function() {
    util.log('Checking for new jobs...');
    dbCheckQueue(function(results) {
        if (results.length) {
            io.sockets.broadcast.send('hello');
        }
    });
}, 10*1000);

However, if the setInterval is to be called from within io.sockets.on('connection',..), every connected client will create an additional loop!

Node.js code

io.sockets.on('connection', function(socket) {
    setInterval(function() {
        util.log('Checking for new jobs...');
        dbCheckQueue(function(results) {
            if (results.length) {
                io.sockets.send('hello');
            }
        });
    }, 10*1000);
});

Clientside JS

        socket.on('hello', function() {
            console.log('HELLO received');
        })

*How can I get a SINGLE loop to run, but still be able to send a message to all connected clients?

  • 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-27T04:05:44+00:00Added an answer on May 27, 2026 at 4:05 am

    I think that this will successfully solve your problem

    io.sockets.emit('hello')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Linq query that will search a column for a word and
I have to write a query to database, that has such table: TABLE HISTORY:
So I have some data that's coming back from a database query, and the
So I have the following linq query that times out when the foreach loop
I am trying to query a database. I already have a file that includes
I have a script that continuously connects to a database and then truncates table
I have a doubt regarding database operation.I have one insert query that should run
I have a loop that reads each line in a file using getline() :
I have a loop that finds duplicate lines in a .ini file. I can
I have a loop that runs through a variety of websites and I'd like

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.