我有以下示例Node.js脚本:

var mdns = require('mdns');

var browser = mdns.createBrowser(mdns.tcp('http'));
browser.on('error', function (error) {
    console.log("error");
    console.log(error);
});
browser.on('serviceUp', function (service) {
    console.log("serviceUp");
    console.log(service);
});
browser.start();

在我的Mac上,它工作正常,并且找到了两个服务。如果我在运行Raspbean的Raspberry PI 2(连接到同一网络)上运行完全相同的脚本,则会得到以下输出:
pi@raspberrypi ~ $ node mdns.js
*** WARNING *** The program 'node' uses the Apple Bonjour compatibility layer of Avahi.
*** WARNING *** Please fix your application to use the native API of Avahi!
*** WARNING *** For more information see <http://0pointer.de/avahi-compat?s=libdns_sd&e=node>
*** WARNING *** The program 'node' called 'DNSServiceRegister()' which is not supported (or only supported partially) in the Apple Bonjour compatibility layer of Avahi.
*** WARNING *** Please fix your application to use the native API of Avahi!
*** WARNING *** For more information see <http://0pointer.de/avahi-compat?s=libdns_sd&e=node&f=DNSServiceRegister>
error
{ [Error: getaddrinfo -3008] code: -3008, errno: -3008, syscall: 'getaddrinfo' }
error
{ [Error: getaddrinfo -3008] code: -3008, errno: -3008, syscall: 'getaddrinfo' }

issue on the mdns GitHub表示忽略警告是公平的。

但是这两个错误呢? Raspberry PI上是否存在某种配置问题?

最佳答案

在本地修改 Node 模块代码是一种不好的做法。

创建mdns浏览器时,最好执行以下操作:

var sequence = [
  mdns.rst.DNSServiceResolve(),
  'DNSServiceGetAddrInfo' in mdns.dns_sd ? mdns.rst.DNSServiceGetAddrInfo() : mdns.rst.getaddrinfo({families:[4]}),
  mdns.rst.makeAddressesUnique()
];
var browser = mdns.createBrowser(mdns.tcp('http'), {resolverSequence: sequence});

就像在此评论中说的:https://github.com/agnat/node_mdns/issues/130#issuecomment-120731155

因此,它将避免错误,并使从事该项目的每个人都可以获得相同的版本,而不必修改本地的mdns代码。

关于node.js - Raspberry PI Mdns getaddrinfo 3008错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29589543/

10-13 04:15