求助帖:怎么创建unix domain socket?
发布于 10 年前 作者 buxkk321 5861 次浏览 最后一次编辑是 8 年前

我直接写 server.listen(‘toPHP.sock’,function(){}); 结果报错

events.js:72 throw er; // Unhandled ‘error’ event ^ Error: listen EACCES at errnoException (net.js:904:11) at Server._listen2 (net.js:1023:19) at listen (net.js:1064:10) at Server.listen (net.js:1132:5) at Object.<anonymous> (D:\wwwroot\nodejs\test1\toPHP.js:20:3) at Module._compile (module.js:456:26) at Object.Module._extensions…js (module.js:474:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) at Function.Module.runMain (module.js:497:10)

用的是xp的系统
5 回复

win不支持unix domain socket.

@whatsmynick 那有没有什么代替的办法呢?win7能用就行

@buxkk321

Windows平台下用命名管道(named pipe)

// 示例代码
// Use domain socket in *nix systems or named pipe in Windows system.
var path;
if (process.platform === 'win32') {
  path = '\\\\.\\pipe\\pipe-test';
} else {
  path = '/tmp/test.sock';
};

var net = require('net');
net.createServer(function(socket) {
  console.log('Connected');
}).listen(path);

@bnuhero 谢谢,这样可以了 不过有点不解 ,为啥要这样写\\.\pipe\ ,有没有哪里有相关的资料我看看?

@buxkk321

这是Windows本地IPC的手段之一,其它还有共享内存等。资料的话,MSDN里面肯定有。

回到顶部