Created
July 30, 2013 21:03
-
-
Save yeco/6116920 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 net = require('net'); | |
// Hace una lista de la gente en el room | |
var clients = []; | |
var server = net.createServer(function(sock){ | |
// Cuando el socket se conecta hacemos unas cuantas cosas... | |
// 1. Establecer un listener para cuando alguien cierre sea removido de la lista | |
sock.on('end', function(){ | |
clients.splice(clients.indexOf(sock), 1); | |
}); | |
// 2. Por cada persona en el room, pasar el data stream al nuevo usuario. | |
// 3. Pasar el stream del nuevo a todos en el room. | |
clients.forEach(function(i){ | |
sock.pipe(i).pipe(sock); | |
}); | |
// 4. Finalmente agregamos al nuevo a la lista. | |
clients.push(sock); | |
}); | |
// Le decimos al server que escuche el puerto 1337. | |
server.listen(1337); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment