2

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

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

有人可以给我一个简单的 Node UDP 广播演示吗?

4

1 回答 1

0

Using punt I tried to bind a connection to 255.255.255.255 on port 5000 and I get this error EADDRNOTAVAIL

I think the address it too general. See this link

Here is the code, which is just a slightly modified version of a punt example.

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);

which yields this error:

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
于 2013-05-29T17:59:35.670 回答