Node.js documentation提供了一个创建回显服务器的示例:
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); });
(加上 'drain' 事件处理、暂停/恢复等 - 参见 docs)
所以 c.pipe(c)
表示“发送到 c 的回显数据”。
关于Node.js 和管道连接监听器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6315388/