Created
January 31, 2010 16:54
-
-
Save gleicon/291145 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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