Skip to content

Instantly share code, notes, and snippets.

@identor
Created March 23, 2015 11:22
Show Gist options
  • Save identor/792b2de56c18bc0125f6 to your computer and use it in GitHub Desktop.
Save identor/792b2de56c18bc0125f6 to your computer and use it in GitHub Desktop.
Share ko lang po sa mga nag aaral ng JavaScript. Pwede din kayo mag Socket programming (NodeJS), eto multi client chat server.
var net = require('net');
var clients = [];
net.createServer(function (socket) {
clients.push(socket);
socket.write('Who are you? ');
socket.on('data', function (message) {
if (!socket.chatname)
return socket.chatname = message.toString().trim();
clients.forEach(function (client) {
client.write(socket.chatname + '> ' + message.toString());
});
});
}).listen(10000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment