Skip to content

Instantly share code, notes, and snippets.

@textarcana
Forked from gleicon/comet_node.js
Created May 12, 2010 04:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save textarcana/398214 to your computer and use it in GitHub Desktop.
Save textarcana/398214 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