Skip to content

Commit

Permalink
created node.js chat
Browse files Browse the repository at this point in the history
  • Loading branch information
Louie van Bommel committed Apr 6, 2012
1 parent 27e7eba commit 5c60c2d
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Scramblelovers Word Games/node/chat.js
@@ -0,0 +1,22 @@
net = require('net');

var sockets = [];

var s = net.Server(function(socket) {
sockets.push(socket);

socket.on('data', function(d) {
for (var i = 0; i < sockets.length; i++) {
if (sockets[i] != socket) {
sockets[i].write(d);
}
}
});

socket.on('end', function() {
var i = sockets.indexOf(socket);
sockets.splice(i, 1);
});
});

s.listen(8000);

0 comments on commit 5c60c2d

Please sign in to comment.