about TCP example in Manual

35 views
Skip to first unread message

wuxu...@gmail.com

unread,
Sep 25, 2014, 1:45:57 AM9/25/14
to nod...@googlegroups.com
my question is that what function of the 'c.pipe(c)' in blow program. if no c.pipe(c), what's the difference? thanks!
var net = require('net');
var server = net.createServer(function(c) { //'connection' listener
  console.log('server connected');
  c.on('end', function() {
    console.log('server disconnected');
  });
  c.write('hello\r\n');
  c.pipe(c);
});
server.listen(8124, function() { //'listening' listener
  console.log('server bound');
});
 

Jimb Esser

unread,
Sep 25, 2014, 1:54:32 PM9/25/14
to nod...@googlegroups.com
c.pipe(c) is reading from c (a single client's socket) and writing that same data back to c, so it's acting as a traditional "echo server" - if you telnet to the server, you should see any data you send echoed back to you after it sends you "hello\n".
Reply all
Reply to author
Forward
0 new messages