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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T21:14:12+00:00 2026-05-21T21:14:12+00:00

A simple function that serves a JSON string from a database result is broadcasted

  • 0

A simple function that serves a JSON string from a database result is broadcasted to the client, using socket.broadcast(). What I wish to do it update the client side when the value changes. Currently, the broadcast function is using setTimeout to broadcast continously every 1 second. Looking at the request logs in Firebug, there is a continuous GET response, which I dont think is a good thing…

Just wondering what the best practice is for using sockets? Are these requests going to kill something? Would a solution be comparing timestamps, or something similar to stop unnecessarily sending requests?

//server-side
function checkData() {
    client.query('SELECT * FROM data', function selectCb(err, data) {
        socket.broadcast(processData(data));
        setTimeout(checkData, 1000);
    });
}

//client-side
socket.on('message', function(data) {
    $('#container').html(JSON.stringify(JSON.parse(data), null));
});

//sample data
[{
    "type":"Statistic1",
    "value":65.2,
    "timestamp":"2011-04-29T16:22:39.000Z"
},{
    "type":"Statistic2",
    "value":18.6,
    "timestamp":"2011-04-29T16:22:39.000Z"
}]

Thanks for your help!

  • 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-21T21:14:13+00:00Added an answer on May 21, 2026 at 9:14 pm

    It depends on the data you are sending. One of the benefits of sockets is that you can choose when to send data to the clients. Save some of the get requests and only broadcast data when you have something new to send.

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

Sidebar

Related Questions

I want a simple function that receives a string and returns an array of
I have a simple function that I want to call in the code behind
I've heard that the static_cast function should be preferred to C-style or simple function-style
In a simple winform application, I call a function that endlessy create files on
I've written an experimental function evaluator that allows me to bind simple functions together
Sample code that shows how to create threads using MFC declares the thread function
I am having an issue trying to post a JSON string using dojo.xhrPost to
I've got a jQuery function that's posting to the server using $.ajax and it
I would like a code sample for a function that takes a tDateTime and
I wrote a sample program at http://codepad.org/ko8vVCDF that uses a template function. How do

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.