Skip to content

Instantly share code, notes, and snippets.

@mranney
Created March 9, 2010 02:19
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 mranney/326079 to your computer and use it in GitHub Desktop.
Save mranney/326079 to your computer and use it in GitHub Desktop.
var sys = require('sys'),
http = require('http'),
pool = [];
function finishTHEM(message){
var pool_size = pool.length, local_r, i;
sys.puts("Sending " + message + " to " + pool_size + " clients.");
for(i = 0; i < pool_size; i += 1) {
local_r = pool.shift();
local_r.write(message);
local_r.close();
}
}
function init(request, response){
if (request.url === '/favicon.ico' ) {
return response.close();
}
response.writeHeader(200, {
'Content-Type': 'text/plain'
});
if (request.url.substr(1,5) === 'send=') {
response.write(String(pool.length));
finishTHEM(request.url.substr(6));
response.close();
}
else {
pool.push(response);
}
}
http.createServer(init).listen(8000, '127.0.0.1');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment