2017-03-26 108 views
0

我已实现了node-ssdpnpm install node-ssdp)的服务器/客户端实现。一切“似乎”都起作用,但我的客户端并没有拿起服务器的数据包。我从不同的设备/位置接收很多其他有效载荷,但没有收到来自我的node-ssdp服务器的有效载荷。节点SSDP客户端未找到服务器广播

我在同一台机器上运行,我在OSX上运行。我有两个独立的节点项目:一个用于我的客户端,一个用于我的服务器。

注意:我也尝试在一台机器上运行服务器,并在另一台机器上运行客户机,以防出现环回等问题。我还通过Wireshark验证来自服务器的数据包正在被客户端机器读取。它在标题中发送一个NOTIFY * HTTP/1.1

这里是我的客户端和服务器的实现:

服务器

var SSDP = require('node-ssdp').Server 
, server = new SSDP({ 
location: 'http://' + require('ip').address() + ':33333', 
ssdpPort: 33333 
}) 
console.log(require('ip').address()) 
server.addUSN('upnp:rootdevice') 
server.addUSN('urn:schemas-upnp-org:device:MediaServer:1') 
server.addUSN('urn:schemas-upnp-org:service:ContentDirectory:1') 
server.addUSN('urn:schemas-upnp-org:service:ConnectionManager:1') 

server.on('advertise-alive', function (heads) { 
    console.log('advertise-alive', heads) 
    // Expire old devices from your cache. 
    // Register advertising device somewhere (as designated in http headers heads) 
}) 

server.on('advertise-bye', function (heads) { 
    console.log('advertise-bye', heads) 
    // Remove specified device from cache. 
}) 

// start server on all interfaces 
console.log('starting ssdp server') 
server.start() 

客户

var ssdp = require('node-ssdp').Client 
    , client = new ssdp({ 
}) 

client.on('notify', function() { 
    //console.log('Got a notification.') 
}) 

client.on('response', function inResponse(headers, code, rinfo) { 
    console.log('Got a response to an m-search:\n%d\n%s\n%s', code, JSON.stringify(headers, null, ' '), JSON.stringify(rinfo, null, ' ')) 
}) 

client.search('ssdp:all') 

// And after 10 seconds, you want to stop 
setTimeout(function() { 
    client.stop() 
}, 10000) 

我运行的想法。这很奇怪,因为我以前实现了一个UDP多播解决方案,并且它可以工作。据我所知,SSDP是幕后的UDP多播。

回答

相关问题