Skip to content

Instantly share code, notes, and snippets.

@gleicon
Created January 31, 2010 16:54
Show Gist options
  • Save gleicon/291145 to your computer and use it in GitHub Desktop.
Save gleicon/291145 to your computer and use it in GitHub Desktop.
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