Node.js和pipe道ConnectionListener

Node.js文档提供了创build回显服务器的示例:

var net = require('net'); var server = net.createServer(function (c) { c.write('hello\r\n'); c.pipe(c); }); server.listen(8124, 'localhost'); 

这条线的用途是什么?

  c.pipe(c); 

c1.pipe(c2) ; 是一个简短的版本

 c1.on('data', function(buf) { c2.write(buf); }); 

(加上'stream失'事件处理,暂停/恢复等 – 见文档 )

所以c.pipe(c)意味着'发送到c'的回声数据。