【问题标题】:EACCES error when sending datagram on Windows在 Windows 上发送数据报时出现 EACCES 错误
【发布时间】: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


【解决方案1】:

我相信从 Windows 7 开始不再支持广播到 255.255.255.255。您需要将发送限制到特定子网。

另外请记住,并非所有路由器都会路由发往255.255.255.255 的数据包。

【讨论】:

    猜你喜欢
    • 2016-05-14
    • 2014-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-16
    相关资源
    最近更新 更多