【发布时间】:2014-09-15 06:26:30
【问题描述】:
我的程序在执行 dgram.udp4 套接字的 send() 方法时抛出 EACCES 错误,但仅在 Windows 上发生。
代码:
var dgram = require('dgram');
var monsocket = dgram.createSocket("udp4");
monsocket.on("listening", function () { comBroadcastCallUp(); });
var comBroadcastCallUp = function() {
var message = new Buffer(JSON.stringify({
protocol: "psdp",
command: "call-up"
}));
monsocket.setBroadcast(true);
monsocket.send(message, 0, message.length, 32681, '255.255.255.255', function (err) {
if (err) console.log(err)
else console.log("<PcStatus:PSDP> Message sent: " + message + os.EOL + "Message length: " + message.length);
});
monsocket.setBroadcast(false);
}
monsocket.bind(32681);
相同的代码,Windows 上的终端输出:
{ [Error: send EACCES] code: 'EACCES', errno: 'EACCES', syscall: 'send' }
Linux 上的终端输出:
<PcStatus:PSDP> Message sent: {"protocol":"psdp","command":"call-up"}
Message length: 39
我检查了防火墙,如果其他程序保持端口繁忙,没有...
【问题讨论】:
-
您是否也尝试过在 Windows 上以管理员身份运行节点,看看是否有所不同?
标签: windows node.js sockets udp