Skip to content

Instantly share code, notes, and snippets.

@ggoodale
Created November 8, 2010 01:16
Show Gist options
  • Save ggoodale/667263 to your computer and use it in GitHub Desktop.
Save ggoodale/667263 to your computer and use it in GitHub Desktop.
Example #1 from Deploy 2010
var net = require('net'), _ = require('./underscore-min')._;
// Our active connections
var connections = {};
var server = net.createServer(function(sock) {
sock.setTimeout(0);
sock.setEncoding("utf8");
connections[sock.remotePort] = sock; // Store a reference to the new client
sock.on('data', function(data) {
_.each(connections, function(receiver) {
if (sock !== receiver) { receiver.write(data); } // Send new data to all other sockets
});
});
sock.on('close', function() { delete connections[this.remotePort]; });
});
server.listen(8124, "0.0.0.0");
console.log("Server started");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment