如何在node.js中创建一个命名管道?
P.S:
现在我创建一个命名管道如下.但我觉得这不是最好的办法
var mkfifoProcess = spawn('mkfifo',[fifoFilePath]); mkfifoProcess.on('exit',function (code) { if (code == 0) { console.log('fifo created: ' + fifoFilePath); } else { console.log('fail to create fifo with code: ' + code); } });
解决方法
看起来像名称管道不是,也不会在Node核心支持 – 从Ben Noordhuis 10/11/11:
Windows has a concept of named pipes but since you mention
mkfifo
I
assume you mean UNIX FIFOs.We don’t support them and probably never will (FIFOs in non-blocking
mode have the potential to deadlock the event loop) but you can use
UNIX sockets if you need similar functionality.
https://groups.google.com/d/msg/nodejs/9TvDwCWaB5c/udQPigFvmgAJ
命名的管道和套接字非常相似,但是net模块通过指定与主机和端口相反的路径来实现本地套接字:
> http://nodejs.org/api/net.html#net_server_listen_path_callback
> http://nodejs.org/api/net.html#net_net_connect_path_connectlistener
例:
var net = require('net'); var server = net.createServer(function(stream) { stream.on('data',function(c) { console.log('data:',c.toString()); }); stream.on('end',function() { server.close(); }); }); server.listen('/tmp/test.sock'); var stream = net.connect('/tmp/test.sock'); stream.write('hello'); stream.end();
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。