Want more features on Pastebin? Sign Up, it's FREE!
Guest

Node.js telnet chat strežnik

By: a guest on Jun 23rd, 2011  |  syntax: JavaScript  |  size: 0.38 KB  |  views: 396  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. net = require('net');
  2.  
  3. var sockets = [];
  4.  
  5. var s = net.Server(function(socket) {
  6.         sockets.push(socket);
  7.  
  8.         socket.on('data', function(d) {
  9.                 for(var i = 0; i < sockets.length; i++) {
  10.                         if(sockets[i] == socket) continue;
  11.                         sockets[i].write(d);           
  12.                 }
  13.         });
  14.        
  15.         socket.on('end', function() {
  16.                 var i = sockets.indexOf(socket);
  17.                 sockets.splice(i, 1);
  18.         });
  19. });
  20.  
  21. s.listen(8000);
clone this paste RAW Paste Data