FAQ
Hello everyone,

I am nee to node.js. Basically my background is Electronics. I am
developing wireless sensor network in which there are 50 nodes (client) and
one server. The main functionality that I want in project is each client
upload some data to server when SERVER ASK THEM TO UPLOAD. This requirement
leads me to explore node.js as it supports pushing data from server to
client. While exploring node.js basic question arise in my mind. I'm
looking forward to get answer from here.

How a server can send data to multiple client at a time..??

How should I begin to develop my server..??

At client side I am running my code on python (UDP client)

How should I proceed to solve this problem..?? At client side I can work
with any protocol as I'm using Raspberry Pi.

Thank you,
Niral

--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+unsubscribe@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/803edb18-ff77-44ce-9c4e-00e1e37766c5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Christopher Rust at Nov 19, 2014 at 6:08 pm
    Hello Niral,

    I'd ask if it's necessary for the server to request the data from the
    clients. If not, then we can really use Node to it's strengths.

    Using Node it's very easy to setup a REST JSON API. Search the internet for
    tutorials using the Express library.

    Then on the client you can use Python to make HTTP requests to the Node
    server delivering the data in a JSON format. The beauty of using node for a
    situation like this is two fold: asynchronous and native JSON.

    JSON is a common HTTP communication format. Drawing the line in the sand
    here, between your server and client, is commonly referred to as loose
    coupling. It doesn't matter what choice of language or tech you use on the
    client side as long as it communicates using JSON HTTP requests.

    Asynchronous means that your Node server, if written correctly, can accept
    many requests at once. This will allow you to scale your sensor network to
    use a large number of clients.

    If you truly need the server to make requests to the sensors then you'll
    need to setup a "server", to accept requests, on the client as well.
    Two-way communication will be more complex.

    Chris
    On Nov 19, 2014 7:35 AM, "Niral Kalavadia" wrote:

    Hello everyone,

    I am nee to node.js. Basically my background is Electronics. I am
    developing wireless sensor network in which there are 50 nodes (client) and
    one server. The main functionality that I want in project is each client
    upload some data to server when SERVER ASK THEM TO UPLOAD. This requirement
    leads me to explore node.js as it supports pushing data from server to
    client. While exploring node.js basic question arise in my mind. I'm
    looking forward to get answer from here.

    How a server can send data to multiple client at a time..??

    How should I begin to develop my server..??

    At client side I am running my code on python (UDP client)

    How should I proceed to solve this problem..?? At client side I can work
    with any protocol as I'm using Raspberry Pi.

    Thank you,
    Niral

    --
    Job board: http://jobs.nodejs.org/
    New group rules:
    https://gist.github.com/othiym23/9886289#file-moderation-policy-md
    Old group rules:
    https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    ---
    You received this message because you are subscribed to the Google Groups
    "nodejs" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to nodejs+unsubscribe@googlegroups.com.
    To post to this group, send email to nodejs@googlegroups.com.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/nodejs/803edb18-ff77-44ce-9c4e-00e1e37766c5%40googlegroups.com
    <https://groups.google.com/d/msgid/nodejs/803edb18-ff77-44ce-9c4e-00e1e37766c5%40googlegroups.com?utm_medium=email&utm_source=footer>
    .
    For more options, visit https://groups.google.com/d/optout.
    --
    Job board: http://jobs.nodejs.org/
    New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
    Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    ---
    You received this message because you are subscribed to the Google Groups "nodejs" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+unsubscribe@googlegroups.com.
    To post to this group, send email to nodejs@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/CAMT%3Dzo4Rqid8D5tvsisOFb-%2B5F7UuSQRtL-Hoi4hb1EAiq%2B7YQ%40mail.gmail.com.
    For more options, visit https://groups.google.com/d/optout.
  • Niral Kalavadia at Nov 20, 2014 at 12:24 pm
    Hello Chris,

    Thank you very much for your inputs.

    Yes it is necessary for server to ask for data to client. This is the only
    mandatory need of my network. Is it possible to use node.js in this
    application?? Is node capable of sending request to multiple client at a
    time???
    On Wednesday, November 19, 2014 11:39:01 PM UTC+5:30, Chris Rust wrote:

    Hello Niral,

    I'd ask if it's necessary for the server to request the data from the
    clients. If not, then we can really use Node to it's strengths.

    Using Node it's very easy to setup a REST JSON API. Search the internet
    for tutorials using the Express library.

    Then on the client you can use Python to make HTTP requests to the Node
    server delivering the data in a JSON format. The beauty of using node for a
    situation like this is two fold: asynchronous and native JSON.

    JSON is a common HTTP communication format. Drawing the line in the sand
    here, between your server and client, is commonly referred to as loose
    coupling. It doesn't matter what choice of language or tech you use on the
    client side as long as it communicates using JSON HTTP requests.

    Asynchronous means that your Node server, if written correctly, can accept
    many requests at once. This will allow you to scale your sensor network to
    use a large number of clients.

    If you truly need the server to make requests to the sensors then you'll
    need to setup a "server", to accept requests, on the client as well.
    Two-way communication will be more complex.

    Chris
    On Nov 19, 2014 7:35 AM, "Niral Kalavadia" <er.ni...@gmail.com
    <javascript:>> wrote:
    Hello everyone,

    I am nee to node.js. Basically my background is Electronics. I am
    developing wireless sensor network in which there are 50 nodes (client) and
    one server. The main functionality that I want in project is each client
    upload some data to server when SERVER ASK THEM TO UPLOAD. This requirement
    leads me to explore node.js as it supports pushing data from server to
    client. While exploring node.js basic question arise in my mind. I'm
    looking forward to get answer from here.

    How a server can send data to multiple client at a time..??

    How should I begin to develop my server..??

    At client side I am running my code on python (UDP client)

    How should I proceed to solve this problem..?? At client side I can work
    with any protocol as I'm using Raspberry Pi.

    Thank you,
    Niral

    --
    Job board: http://jobs.nodejs.org/
    New group rules:
    https://gist.github.com/othiym23/9886289#file-moderation-policy-md
    Old group rules:
    https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    ---
    You received this message because you are subscribed to the Google Groups
    "nodejs" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to nodejs+un...@googlegroups.com <javascript:>.
    To post to this group, send email to nod...@googlegroups.com
    <javascript:>.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/nodejs/803edb18-ff77-44ce-9c4e-00e1e37766c5%40googlegroups.com
    <https://groups.google.com/d/msgid/nodejs/803edb18-ff77-44ce-9c4e-00e1e37766c5%40googlegroups.com?utm_medium=email&utm_source=footer>
    .
    For more options, visit https://groups.google.com/d/optout.
    --
    Job board: http://jobs.nodejs.org/
    New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
    Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    ---
    You received this message because you are subscribed to the Google Groups "nodejs" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+unsubscribe@googlegroups.com.
    To post to this group, send email to nodejs@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/02e4f56f-abb0-44f2-b44b-0d782561ad71%40googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Ryan Schmidt at Nov 20, 2014 at 12:46 pm

    On Nov 20, 2014, at 4:02 AM, Niral Kalavadia wrote:

    Yes it is necessary for server to ask for data to client. This is the only mandatory need of my network. Is it possible to use node.js in this application?? Is node capable of sending request to multiple client at a time???
    Yes, and yes. You can write any code you want to, in most any language. :)

    If your server is an http server written in node, and your client is a modern web browser, then the already-mentioned socket.io library is a popular way to achieve this goal. If your client and server are not talking http to one another, if your client is not a modern web browser, then you may need a different library, or you may need to write the communication code yourself.

    --
    Job board: http://jobs.nodejs.org/
    New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
    Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    ---
    You received this message because you are subscribed to the Google Groups "nodejs" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+unsubscribe@googlegroups.com.
    To post to this group, send email to nodejs@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/0BAFA85C-9496-4040-AF3B-69F8493B4362%40ryandesign.com.
    For more options, visit https://groups.google.com/d/optout.
  • Will Hoover at Nov 20, 2014 at 3:35 pm
    Just to add to Ryan's comments...

    If you do decide to use a modern web browser as your client (and you don't
    care about Internet Exploder support) you can use SSEs. The beauty of using
    SSE is that if your server goes down or a connection is lost the SSE client
    will reconnect automatically:

    require('http').createServer(function (req, res) {
         if (req.headers.accept && req.headers.accept == 'text/event-stream') {
             res.writeHead(200, {
                 'Content-Type': 'text/event-stream',
                 'Cache-Control': 'no-cache',
                 'Connection': 'keep-alive'
             });
             var id = 0;
             setInterval(sse, 5000);
             // or: process.nextTick(sse);
             sse();
             function sse() {
                 res.write('id: ' + ++id + '\n');
                 res.write("data: " + new Date().toUTCString() + '\n\n');
             }
         } else {
             res.writeHead(200, { 'Content-Type': 'text/html' });
             res.write('<!DOCTYPE html><html><head>' +
                 '<script>' +
                     'new
    EventSource("/").addEventListener("message",function(event) {' +
                         'document.getElementById("sse").innerHTML=event.data' +
                     '});' +
                 '</script>' +
                 '</head><body><div id="sse">Waiting...</div></body></html>');
             res.end();
         }
    }).listen(9080);

    On Thursday, November 20, 2014 7:46:31 AM UTC-5, ryandesign wrote:

    On Nov 20, 2014, at 4:02 AM, Niral Kalavadia wrote:

    Yes it is necessary for server to ask for data to client. This is the
    only mandatory need of my network. Is it possible to use node.js in this
    application?? Is node capable of sending request to multiple client at a
    time???

    Yes, and yes. You can write any code you want to, in most any language. :)

    If your server is an http server written in node, and your client is a
    modern web browser, then the already-mentioned socket.io library is a
    popular way to achieve this goal. If your client and server are not talking
    http to one another, if your client is not a modern web browser, then you
    may need a different library, or you may need to write the communication
    code yourself.
    --
    Job board: http://jobs.nodejs.org/
    New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
    Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    ---
    You received this message because you are subscribed to the Google Groups "nodejs" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+unsubscribe@googlegroups.com.
    To post to this group, send email to nodejs@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/15a73231-8332-441b-92cf-b28931025a79%40googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Will Hoover at Nov 20, 2014 at 6:06 pm
    Sorry, noticed that you want them sent at the same time:

    var clients = [];
    require('http').createServer(function (req, res) {
         if (req.headers.accept && req.headers.accept == 'text/event-stream') {
             res.writeHead(200, {
                 'Content-Type': 'text/event-stream',
                 'Cache-Control': 'no-cache',
                 'Connection': 'keep-alive'
             });
             clients.push(res);
             req.on('close', function reqClosed() {
                 clients.splice(clients.indexOf(res), 1);
             });
         } else {
             res.writeHead(200, { 'Content-Type': 'text/html' });
             res.write('<!DOCTYPE html><html><head>' +
                 '<script>' +
                     'new
    EventSource("/").addEventListener("message",function(event) {' +
                         'document.getElementById("sse").innerHTML=event.data' +
                     '});' +
                 '</script>' +
                 '</head><body><div id="sse">Waiting...</div></body></html>');
             res.end();
         }
    }).listen(9080);
    setInterval(function sse() {
         if (!clients.length) {
             return;
         }
         var dt = new Date().toUTCString();
         for (var i = 0; i < clients.length; i++) {
             clients[i].write("data: " + dt + '\n\n');
         }
    }, 5000);

    On Thursday, November 20, 2014 10:11:48 AM UTC-5, Will Hoover wrote:

    Just to add to Ryan's comments...

    If you do decide to use a modern web browser as your client (and you don't
    care about Internet Exploder support) you can use SSEs. The beauty of using
    SSE is that if your server goes down or a connection is lost the SSE client
    will reconnect automatically:

    require('http').createServer(function (req, res) {
    if (req.headers.accept && req.headers.accept == 'text/event-stream') {
    res.writeHead(200, {
    'Content-Type': 'text/event-stream',
    'Cache-Control': 'no-cache',
    'Connection': 'keep-alive'
    });
    var id = 0;
    setInterval(sse, 5000);
    // or: process.nextTick(sse);
    sse();
    function sse() {
    res.write('id: ' + ++id + '\n');
    res.write("data: " + new Date().toUTCString() + '\n\n');
    }
    } else {
    res.writeHead(200, { 'Content-Type': 'text/html' });
    res.write('<!DOCTYPE html><html><head>' +
    '<script>' +
    'new
    EventSource("/").addEventListener("message",function(event) {' +
    'document.getElementById("sse").innerHTML=event.data'
    +
    '});' +
    '</script>' +
    '</head><body><div id="sse">Waiting...</div></body></html>');
    res.end();
    }
    }).listen(9080);

    On Thursday, November 20, 2014 7:46:31 AM UTC-5, ryandesign wrote:

    On Nov 20, 2014, at 4:02 AM, Niral Kalavadia wrote:

    Yes it is necessary for server to ask for data to client. This is the
    only mandatory need of my network. Is it possible to use node.js in this
    application?? Is node capable of sending request to multiple client at a
    time???

    Yes, and yes. You can write any code you want to, in most any language.
    :)

    If your server is an http server written in node, and your client is a
    modern web browser, then the already-mentioned socket.io library is a
    popular way to achieve this goal. If your client and server are not talking
    http to one another, if your client is not a modern web browser, then you
    may need a different library, or you may need to write the communication
    code yourself.
    --
    Job board: http://jobs.nodejs.org/
    New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
    Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    ---
    You received this message because you are subscribed to the Google Groups "nodejs" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+unsubscribe@googlegroups.com.
    To post to this group, send email to nodejs@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/5624ecaa-62f2-4132-954f-ce9c4c8c51e8%40googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Svante karlsson at Nov 20, 2014 at 7:40 pm
    Since you are speaking of sensor networks, MQTT is a "perfect" fit for what
    you want.

    This can easily be done in any language (a lot at least) but if you would
    like js take a look at:

    https://github.com/adamvr/MQTT.js/

    The example is almost what you ask for. Let the client (sensor) subscribe
    to a message - "sample"

    Have another client (controller) running on the serverside that publishes
    those messages

    client.publish('sample', 'ts');

    all sensors will get that message more or less at the same time and they
    will then publish their samples under a topic like "deviceid/data"

    works with both tcp and ssl, if you want to do this over public network and
    has a low protocol overhead.

    /svante



    2014-11-20 17:42 GMT+01:00 Will Hoover <js.whoover@gmail.com>:
    Sorry, noticed that you want them sent at the same time:

    var clients = [];
    require('http').createServer(function (req, res) {
    if (req.headers.accept && req.headers.accept == 'text/event-stream') {
    res.writeHead(200, {
    'Content-Type': 'text/event-stream',
    'Cache-Control': 'no-cache',
    'Connection': 'keep-alive'
    });
    clients.push(res);
    req.on('close', function reqClosed() {
    clients.splice(clients.indexOf(res), 1);
    });
    } else {
    res.writeHead(200, { 'Content-Type': 'text/html' });
    res.write('<!DOCTYPE html><html><head>' +
    '<script>' +
    'new
    EventSource("/").addEventListener("message",function(event) {' +
    'document.getElementById("sse").innerHTML=event.data'
    +
    '});' +
    '</script>' +
    '</head><body><div id="sse">Waiting...</div></body></html>');
    res.end();
    }
    }).listen(9080);
    setInterval(function sse() {
    if (!clients.length) {
    return;
    }
    var dt = new Date().toUTCString();
    for (var i = 0; i < clients.length; i++) {
    clients[i].write("data: " + dt + '\n\n');
    }
    }, 5000);

    On Thursday, November 20, 2014 10:11:48 AM UTC-5, Will Hoover wrote:

    Just to add to Ryan's comments...

    If you do decide to use a modern web browser as your client (and you
    don't care about Internet Exploder support) you can use SSEs. The beauty of
    using SSE is that if your server goes down or a connection is lost the SSE
    client will reconnect automatically:

    require('http').createServer(function (req, res) {
    if (req.headers.accept && req.headers.accept == 'text/event-stream')
    {
    res.writeHead(200, {
    'Content-Type': 'text/event-stream',
    'Cache-Control': 'no-cache',
    'Connection': 'keep-alive'
    });
    var id = 0;
    setInterval(sse, 5000);
    // or: process.nextTick(sse);
    sse();
    function sse() {
    res.write('id: ' + ++id + '\n');
    res.write("data: " + new Date().toUTCString() + '\n\n');
    }
    } else {
    res.writeHead(200, { 'Content-Type': 'text/html' });
    res.write('<!DOCTYPE html><html><head>' +
    '<script>' +
    'new EventSource("/").addEventListener("message",function(event)
    {' +
    'document.getElementById("sse").innerHTML=event.data'
    +
    '});' +
    '</script>' +
    '</head><body><div id="sse">Waiting...</div></body></html>');
    res.end();
    }
    }).listen(9080);

    On Thursday, November 20, 2014 7:46:31 AM UTC-5, ryandesign wrote:

    On Nov 20, 2014, at 4:02 AM, Niral Kalavadia wrote:

    Yes it is necessary for server to ask for data to client. This is the
    only mandatory need of my network. Is it possible to use node.js in this
    application?? Is node capable of sending request to multiple client at a
    time???

    Yes, and yes. You can write any code you want to, in most any language.
    :)

    If your server is an http server written in node, and your client is a
    modern web browser, then the already-mentioned socket.io library is a
    popular way to achieve this goal. If your client and server are not talking
    http to one another, if your client is not a modern web browser, then you
    may need a different library, or you may need to write the communication
    code yourself.

    --
    Job board: http://jobs.nodejs.org/
    New group rules:
    https://gist.github.com/othiym23/9886289#file-moderation-policy-md
    Old group rules:
    https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    ---
    You received this message because you are subscribed to the Google Groups
    "nodejs" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to nodejs+unsubscribe@googlegroups.com.
    To post to this group, send email to nodejs@googlegroups.com.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/nodejs/5624ecaa-62f2-4132-954f-ce9c4c8c51e8%40googlegroups.com
    <https://groups.google.com/d/msgid/nodejs/5624ecaa-62f2-4132-954f-ce9c4c8c51e8%40googlegroups.com?utm_medium=email&utm_source=footer>
    .

    For more options, visit https://groups.google.com/d/optout.
    --
    Job board: http://jobs.nodejs.org/
    New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
    Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    ---
    You received this message because you are subscribed to the Google Groups "nodejs" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+unsubscribe@googlegroups.com.
    To post to this group, send email to nodejs@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/CAHkETj9rrTDejTJ7k_bSsf%3DSABnkmDf%2BX8Jw6-ZG8G71hNudmA%40mail.gmail.com.
    For more options, visit https://groups.google.com/d/optout.
  • Niral Kalavadia at Nov 21, 2014 at 7:54 am
    Thank you very much.. MQTT.js seems that it will do for me..
    On Friday, November 21, 2014 1:11:14 AM UTC+5:30, svante karlsson wrote:

    Since you are speaking of sensor networks, MQTT is a "perfect" fit for
    what you want.

    This can easily be done in any language (a lot at least) but if you would
    like js take a look at:

    https://github.com/adamvr/MQTT.js/

    The example is almost what you ask for. Let the client (sensor) subscribe
    to a message - "sample"

    Have another client (controller) running on the serverside that publishes
    those messages

    client.publish('sample', 'ts');

    all sensors will get that message more or less at the same time and they
    will then publish their samples under a topic like "deviceid/data"

    works with both tcp and ssl, if you want to do this over public network
    and has a low protocol overhead.

    /svante



    2014-11-20 17:42 GMT+01:00 Will Hoover <js.wh...@gmail.com <javascript:>>:
    Sorry, noticed that you want them sent at the same time:

    var clients = [];
    require('http').createServer(function (req, res) {
    if (req.headers.accept && req.headers.accept == 'text/event-stream')
    {
    res.writeHead(200, {
    'Content-Type': 'text/event-stream',
    'Cache-Control': 'no-cache',
    'Connection': 'keep-alive'
    });
    clients.push(res);
    req.on('close', function reqClosed() {
    clients.splice(clients.indexOf(res), 1);
    });
    } else {
    res.writeHead(200, { 'Content-Type': 'text/html' });
    res.write('<!DOCTYPE html><html><head>' +
    '<script>' +
    'new
    EventSource("/").addEventListener("message",function(event) {' +
    'document.getElementById("sse").innerHTML=event.data'
    +
    '});' +
    '</script>' +
    '</head><body><div id="sse">Waiting...</div></body></html>');
    res.end();
    }
    }).listen(9080);
    setInterval(function sse() {
    if (!clients.length) {
    return;
    }
    var dt = new Date().toUTCString();
    for (var i = 0; i < clients.length; i++) {
    clients[i].write("data: " + dt + '\n\n');
    }
    }, 5000);

    On Thursday, November 20, 2014 10:11:48 AM UTC-5, Will Hoover wrote:

    Just to add to Ryan's comments...

    If you do decide to use a modern web browser as your client (and you
    don't care about Internet Exploder support) you can use SSEs. The beauty of
    using SSE is that if your server goes down or a connection is lost the SSE
    client will reconnect automatically:

    require('http').createServer(function (req, res) {
    if (req.headers.accept && req.headers.accept == 'text/event-stream')
    {
    res.writeHead(200, {
    'Content-Type': 'text/event-stream',
    'Cache-Control': 'no-cache',
    'Connection': 'keep-alive'
    });
    var id = 0;
    setInterval(sse, 5000);
    // or: process.nextTick(sse);
    sse();
    function sse() {
    res.write('id: ' + ++id + '\n');
    res.write("data: " + new Date().toUTCString() + '\n\n');
    }
    } else {
    res.writeHead(200, { 'Content-Type': 'text/html' });
    res.write('<!DOCTYPE html><html><head>' +
    '<script>' +
    'new EventSource("/").addEventListener("message",function(event)
    {' +
    'document.getElementById("sse"
    ).innerHTML=event.data' +
    '});' +
    '</script>' +
    '</head><body><div id="sse">Waiting...</div></body></html>'
    );
    res.end();
    }
    }).listen(9080);

    On Thursday, November 20, 2014 7:46:31 AM UTC-5, ryandesign wrote:

    On Nov 20, 2014, at 4:02 AM, Niral Kalavadia wrote:

    Yes it is necessary for server to ask for data to client. This is the
    only mandatory need of my network. Is it possible to use node.js in this
    application?? Is node capable of sending request to multiple client at a
    time???

    Yes, and yes. You can write any code you want to, in most any language.
    :)

    If your server is an http server written in node, and your client is a
    modern web browser, then the already-mentioned socket.io library is a
    popular way to achieve this goal. If your client and server are not talking
    http to one another, if your client is not a modern web browser, then you
    may need a different library, or you may need to write the communication
    code yourself.

    --
    Job board: http://jobs.nodejs.org/
    New group rules:
    https://gist.github.com/othiym23/9886289#file-moderation-policy-md
    Old group rules:
    https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    ---
    You received this message because you are subscribed to the Google Groups
    "nodejs" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to nodejs+un...@googlegroups.com <javascript:>.
    To post to this group, send email to nod...@googlegroups.com
    <javascript:>.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/nodejs/5624ecaa-62f2-4132-954f-ce9c4c8c51e8%40googlegroups.com
    <https://groups.google.com/d/msgid/nodejs/5624ecaa-62f2-4132-954f-ce9c4c8c51e8%40googlegroups.com?utm_medium=email&utm_source=footer>
    .

    For more options, visit https://groups.google.com/d/optout.
    --
    Job board: http://jobs.nodejs.org/
    New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
    Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    ---
    You received this message because you are subscribed to the Google Groups "nodejs" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+unsubscribe@googlegroups.com.
    To post to this group, send email to nodejs@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/5fdb3fd8-8d1a-4eb7-bf93-7e1a7b6bbb38%40googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Niral Kalavadia at Nov 21, 2014 at 7:54 am
    Hello Will,

    Thank you very much..
    On Thursday, November 20, 2014 10:12:46 PM UTC+5:30, Will Hoover wrote:

    Sorry, noticed that you want them sent at the same time:

    var clients = [];
    require('http').createServer(function (req, res) {
    if (req.headers.accept && req.headers.accept == 'text/event-stream') {
    res.writeHead(200, {
    'Content-Type': 'text/event-stream',
    'Cache-Control': 'no-cache',
    'Connection': 'keep-alive'
    });
    clients.push(res);
    req.on('close', function reqClosed() {
    clients.splice(clients.indexOf(res), 1);
    });
    } else {
    res.writeHead(200, { 'Content-Type': 'text/html' });
    res.write('<!DOCTYPE html><html><head>' +
    '<script>' +
    'new
    EventSource("/").addEventListener("message",function(event) {' +
    'document.getElementById("sse").innerHTML=event.data'
    +
    '});' +
    '</script>' +
    '</head><body><div id="sse">Waiting...</div></body></html>');
    res.end();
    }
    }).listen(9080);
    setInterval(function sse() {
    if (!clients.length) {
    return;
    }
    var dt = new Date().toUTCString();
    for (var i = 0; i < clients.length; i++) {
    clients[i].write("data: " + dt + '\n\n');
    }
    }, 5000);

    On Thursday, November 20, 2014 10:11:48 AM UTC-5, Will Hoover wrote:

    Just to add to Ryan's comments...

    If you do decide to use a modern web browser as your client (and you
    don't care about Internet Exploder support) you can use SSEs. The beauty of
    using SSE is that if your server goes down or a connection is lost the SSE
    client will reconnect automatically:

    require('http').createServer(function (req, res) {
    if (req.headers.accept && req.headers.accept == 'text/event-stream')
    {
    res.writeHead(200, {
    'Content-Type': 'text/event-stream',
    'Cache-Control': 'no-cache',
    'Connection': 'keep-alive'
    });
    var id = 0;
    setInterval(sse, 5000);
    // or: process.nextTick(sse);
    sse();
    function sse() {
    res.write('id: ' + ++id + '\n');
    res.write("data: " + new Date().toUTCString() + '\n\n');
    }
    } else {
    res.writeHead(200, { 'Content-Type': 'text/html' });
    res.write('<!DOCTYPE html><html><head>' +
    '<script>' +
    'new
    EventSource("/").addEventListener("message",function(event) {' +
    'document.getElementById("sse").innerHTML=event.data'
    +
    '});' +
    '</script>' +
    '</head><body><div id="sse">Waiting...</div></body></html>');
    res.end();
    }
    }).listen(9080);

    On Thursday, November 20, 2014 7:46:31 AM UTC-5, ryandesign wrote:

    On Nov 20, 2014, at 4:02 AM, Niral Kalavadia wrote:

    Yes it is necessary for server to ask for data to client. This is the
    only mandatory need of my network. Is it possible to use node.js in this
    application?? Is node capable of sending request to multiple client at a
    time???

    Yes, and yes. You can write any code you want to, in most any language.
    :)

    If your server is an http server written in node, and your client is a
    modern web browser, then the already-mentioned socket.io library is a
    popular way to achieve this goal. If your client and server are not talking
    http to one another, if your client is not a modern web browser, then you
    may need a different library, or you may need to write the communication
    code yourself.
    --
    Job board: http://jobs.nodejs.org/
    New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
    Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    ---
    You received this message because you are subscribed to the Google Groups "nodejs" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+unsubscribe@googlegroups.com.
    To post to this group, send email to nodejs@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/328e109a-0466-4b97-a208-1a00e9f09af7%40googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • FELIPE TORRES at Nov 20, 2014 at 12:24 pm
    To develop a reliable two-side communication system, i'd look into
    socket.io as al alternative
    I've used plenty of times and found little to no problems on implementing
    and develop with it.
    Although you need a stable connection between the server and the client.

    I'd give it a go :)



    El miércoles, 19 de noviembre de 2014 09:00:32 UTC-3, Niral Kalavadia
    escribió:
    Hello everyone,

    I am nee to node.js. Basically my background is Electronics. I am
    developing wireless sensor network in which there are 50 nodes (client) and
    one server. The main functionality that I want in project is each client
    upload some data to server when SERVER ASK THEM TO UPLOAD. This requirement
    leads me to explore node.js as it supports pushing data from server to
    client. While exploring node.js basic question arise in my mind. I'm
    looking forward to get answer from here.

    How a server can send data to multiple client at a time..??

    How should I begin to develop my server..??

    At client side I am running my code on python (UDP client)

    How should I proceed to solve this problem..?? At client side I can work
    with any protocol as I'm using Raspberry Pi.

    Thank you,
    Niral
    --
    Job board: http://jobs.nodejs.org/
    New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
    Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    ---
    You received this message because you are subscribed to the Google Groups "nodejs" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+unsubscribe@googlegroups.com.
    To post to this group, send email to nodejs@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/46d041b9-1dba-4e7b-80dd-134fc8168beb%40googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Niral Kalavadia at Nov 21, 2014 at 7:54 am
    Hello Felipe,

    Thanks a lot for your inputs..
    On Thursday, November 20, 2014 4:23:19 PM UTC+5:30, FELIPE TORRES wrote:

    To develop a reliable two-side communication system, i'd look into
    socket.io as al alternative
    I've used plenty of times and found little to no problems on implementing
    and develop with it.
    Although you need a stable connection between the server and the client.

    I'd give it a go :)



    El miércoles, 19 de noviembre de 2014 09:00:32 UTC-3, Niral Kalavadia
    escribió:
    Hello everyone,

    I am nee to node.js. Basically my background is Electronics. I am
    developing wireless sensor network in which there are 50 nodes (client) and
    one server. The main functionality that I want in project is each client
    upload some data to server when SERVER ASK THEM TO UPLOAD. This requirement
    leads me to explore node.js as it supports pushing data from server to
    client. While exploring node.js basic question arise in my mind. I'm
    looking forward to get answer from here.

    How a server can send data to multiple client at a time..??

    How should I begin to develop my server..??

    At client side I am running my code on python (UDP client)

    How should I proceed to solve this problem..?? At client side I can work
    with any protocol as I'm using Raspberry Pi.

    Thank you,
    Niral
    --
    Job board: http://jobs.nodejs.org/
    New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
    Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    ---
    You received this message because you are subscribed to the Google Groups "nodejs" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+unsubscribe@googlegroups.com.
    To post to this group, send email to nodejs@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/6d46f461-7ef7-4f74-a906-bc1a19135f4f%40googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupnodejs @
categoriesnodejs
postedNov 19, '14 at 1:35p
activeNov 21, '14 at 7:54a
posts11
users6
websitenodejs.org
irc#node.js

People

Translate

site design / logo © 2022 Grokbase