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
--
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.
To post to this group, send email to nod...@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.
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);
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);
--
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.
To post to this group, send email to nod...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/5624ecaa-62f2-4132-954f-ce9c4c8c51e8%40googlegroups.com.