Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
var sys = require("sys");
var http = require("http");
var connections=[];
function update() {
if (connections.length) {
connections.forEach(function(c) {
sys.puts(JSON.stringify(c));
c.sendBody('oi\n');
});
}
setTimeout(update, 1000);
}
setTimeout(update, 1000);
http.createServer(function(req, res) {
if (req.url == '/clock') {
req.connection.setTimeout(0);
res.sendHeader(200, {'Content-type':'text/plain'});
connections.push(res);
} else {
res.sendHeader(404, {'Content-type':'text/plain'});
res.sendBody('not found');
res.finish();
}
}).listen(8888);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment