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 <[email protected]>:

> 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 [email protected].
> To post to this group, send email to [email protected].
> 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 [email protected].
To post to this group, send email to [email protected].
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.

Reply via email to