Created
March 23, 2015 11:22
-
-
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.
This file contains hidden or 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'); | |
| 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