【问题标题】:Sending and receiving a UDP broadcast to and from 255.255.255.255 in Node.js在 Node.js 中向 255.255.255.255 发送和接收 UDP 广播
【发布时间】:2013-05-22 09:15:13
【问题描述】:

我正在尝试在 Node 中实现一个 BOOTP 服务器,对此广播是必要的。可悲的是,文档有点令人困惑,而且我一路上都遇到了奇怪的错误。有趣的是,Windows 7 和 Ubuntu 上的错误是不同的。

是否有人真的设法将 UDP 广播发送到 255.255.255.255 或在此地址下接收?

谁能给我一个简单的 Node UDP 广播演示?

【问题讨论】:

    标签: node.js udp ip broadcasting


    【解决方案1】:

    使用punt 我尝试在端口5000 上绑定到255.255.255.255 的连接,我收到此错误EADDRNOTAVAIL

    我觉得这个地址太笼统了。看到这个link

    这是代码,它只是punt 示例的略微修改版本。

    var punt = require('punt');
    var server = punt.bind('255.255.255.255:5000');
    var a = punt.connect('255.255.255.255:5000');
    
    server.on('message', function(msg){
      console.log(msg);
    });
    
    setInterval(function(){
      a.send({ hello: 'world' });
    }, 150);
    

    产生此错误:

    events.js:72
            throw er; // Unhandled 'error' event
                  ^
    Error: bind EADDRNOTAVAIL
        at errnoException (dgram.js:439:11)
        at dgram.js:206:28
        at dns.js:72:18
        at process._tickCallback (node.js:415:13)
        at Function.Module.runMain (module.js:499:11)
        at startup (node.js:119:16)
        at node.js:901:3
    

    【讨论】:

    • EADDRNOTAVAIL 与我在 Windows 机器上遇到的错误相同。但是,您是否设法向192.168.1.255 广播?剩下的问题是,BOOTP 仅根据RFC 951 向255.255.255.255 广播。
    猜你喜欢
    • 2018-05-29
    • 2020-02-21
    • 2021-07-30
    • 1970-01-01
    • 2011-10-02
    • 2012-06-05
    • 2011-12-07
    • 2015-03-14
    • 1970-01-01
    相关资源
    最近更新 更多