Skip to content

Instantly share code, notes, and snippets.

@bridgpal
Created August 30, 2013 22:48
Show Gist options
  • Save bridgpal/6395036 to your computer and use it in GitHub Desktop.
Save bridgpal/6395036 to your computer and use it in GitHub Desktop.
var net = require('net');
var clients = [];
var server = net.createServer(function(socket) {
//add any incoming socket to a clients array
clients.push(socket);
socket.on('data', function (data) {
//iterate over a list of clients and send data
for(var i = 0; i < clients.length; i++) {
clients[i].write(data);
}
});
socket.on('end', function() {
var i = clients.indexOf(socket)
clients.splice(i,1);
});
});
server.listen(8000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment