小编Meh*_*dar的帖子

在 Unix 域套接字上调用 open() 失败,并出现错误“没有此类设备或地址”

我正在尝试在 Linux 中使用命名管道在 NodeJS 和 C 程序之间进行通信。我的服务器程序是用 NodeJS 编写的:

'use strict';

const net = require('net');
const pipename = '/tmp/pipe1';
const fs = require('fs');

let server = net.createServer(function(socket){
        console.log('A new connection');
        socket.on('data',function(data){
                console.log(data.toString());
        });
        socket.on('end',function(){
                console.log('Closed connection');
        });
});

server.on('error',console.log);

fs.unlink(pipename,function(){
        server.listen(pipename);
})

//Test unix-socket server:
setInterval(function(){
        var stream = net.connect(pipename);
        stream.on('error',console.log);
        stream.write('hello');
        stream.end();
},2000);
Run Code Online (Sandbox Code Playgroud)

但是,当我想在 NodeJS 服务器已经启动后打开 C 内部的管道时,我收到错误:

const char* pipename = "/tmp/pipe1";
int hPipe = open(pipename, O_WRONLY); //Error: No such device or address
Run Code Online (Sandbox Code Playgroud)

当我尝试去做时echo 'Hello World!' > …

c++ bash ipc unix-socket node.js

1
推荐指数
1
解决办法
773
查看次数

标签 统计

bash ×1

c++ ×1

ipc ×1

node.js ×1

unix-socket ×1