Not getting "response" event
ChriD opened this issue ยท 13 comments
Hi,
I am having troubles getting the "response" event on the client
I am doing a search on the client
var client = new Client({customLogger: logx});
client.search('urn:schemas-upnp-org:device:MediaRenderer:1');
client.on('notify', function () {
console.log('Got a notification.')
})
client.on('response', function inResponse() {
console.log('response');
})
client.on('advertise-alive', function inResponse() {
console.log('advertise-alive');
})
client.on('advertise-bye', function inResponse() {
console.log('advertise-bye');
})
client.on('m-search', function inResponse() {
console.log('m-search');
})
and the log i am getting is this one
SSDP listening: %o {"address":"http://0.0.0.0:1900","interface":"192.168.56.1"}
SSDP listening: %o {"address":"http://0.0.0.0:1900","interface":"10.0.0.4"}
Sending an M-SEARCH request undefined
Sent M-SEARCH request: %o {"message":"M-SEARCH * HTTP/1.1\r\nHOST: 239.255.255.250:1900\r\nST: urn:schemas-upnp-org:device:MediaRenderer:1\r\nMAN: \"ssdp:discover\"\r\nMX: 3\r\n\r\n"}
SSDP M-SEARCH event: %o {"ST":"urn:schemas-upnp-org:device:MediaRenderer:1","address":"10.0.0.4","port":1900}
SSDP M-SEARCH event: %o {"ST":"urn:schemas-upnp-org:device:MediaRenderer:1","address":"10.0.0.4","port":1900}
SSDP M-SEARCH event: %o {"ST":"upnp:rootdevice","address":"10.0.0.111","port":38182}
SSDP M-SEARCH event: %o {"ST":"upnp:rootdevice","address":"10.0.0.111","port":38182}
SSDP M-SEARCH event: %o {"ST":"upnp:rootdevice","address":"10.0.0.111","port":38182}
SSDP M-SEARCH event: %o {"ST":"upnp:rootdevice","address":"10.0.0.111","port":38182}
SSDP M-SEARCH event: %o {"ST":"ssdp:all","address":"10.0.0.111","port":53319}
SSDP M-SEARCH event: %o {"ST":"upnp:rootdevice","address":"10.0.0.111","port":54712}
SSDP M-SEARCH event: %o {"ST":"upnp:rootdevice","address":"10.0.0.111","port":54712}
So it seems that i am getting 2 Media Renderers Search events which should trigger the "response" event? But the response is nerver been called?
What i am doeing wrong? I tried several branches and the current stable package. All behave a little bit different.
I have a Virtual Ethernet Adapter. If i am deactivating this adapter the problem persists.
Any Idea?
Hi Chris!
Can you tell me a little more about what you expect to see โ is there a device on your network that you expect to respond to this search?
Can you tell me your router make/model, too, please?
Of course!
I have a HUAWAI HA35-22/AM (AV1HA35M VER.A) (A hybrid router DSL+4G)
And i am trying to find all media renderers on the 10.0.0x network.
I'am expection to get the "response" even for the devices/services (of course only the Renderers) as given by the Intel UPNP device Spy. That should be 3 Media Renderers as marked in the screenshot
Bu as you can see i only get 2 MediaRenderers Search Events and for those 2 the "response" event is not getting called
After a while (~20 seconds) i get a lots of advertise alive events very fast
When i turn on a new Media Renderer, it will not be recognized either but i get again a lot of advertise alive events (but in this case immediately when turning on the renderer) But i never get any response event as i should get like in the client example.
I have tried to disable the firewall and to start node with admin rights. The same behaviour.
But it should not be a problem with the firewall or admin rights at all because the Intel Device Spy and the openHome UPNP Stack can find the devices.
I have also tried to disable the VirtualBox Network Adapter with the same results
I'm not sure whats the problem here..
EDIT:
I have used wireshar to check the SSDP protocols. The NodeJs Server sends out a search and the Renderer-Services and all other Services are respnding. I am not sure why 2 M-SEARCHES are posted but that should not be a problem?
As you can see the 10.0.0.111, 10.0.0.138, 10.0.0.203. 10.0.0.202 and 10.0.0.201 are answering to the M-SEARCH (wherby the 201-203 are the renderers)
EDIT2:
I search a alittle further and i created a simple test script with dgram using udp4
It seems that only responses on 239.255.255.250 are received in the socket.
So the behaviour in my test script is the same as in this library. So marked lines are received but the "real" responses are not?
I have no clue wht the problem might be?!
For some further test i tried to bind directly to the "10.0.0.4" address but of couse the is an error that there is already something bind to that address and port (Windos UPNP Listener)- But its ver interesting that the Intel Device Spy can bind to that port.
As you can see there are different Processes listening on the same port.
It seems that somesthing on my pc? is "swallowing" the responses?
SOLUTION?
Well in fact if i deactivate following service
it works. So it seems that this is the problem. But why do other SSDP Searches work when this service is activated (eg. opehHome UPNP Stack or Intel UPNP Device Spy?, In fact they open the same port (which seems not to be possible in node?))
In my opinion it should work with this service on too. But this may be a limitation in the "dgram" lib?
This is all great stuff, @ChriD, thank you for going to such lengths to investigate! ๐
To test binding to 10.0.0.4
you'll need to pass reuseAddr
when creating a socket, like so https://github.com/diversario/node-ssdp/blob/master/lib/index.js#L158
I find it interesting that disabling Window's SSDP service fixes the problem. As far as I know, multicast messages are multiplexed to all listeners bound to a socket, so even if there's already another service listening it shouldn't interfere with others.
One thing to try is explicitSocketBind: true
constructor option:
const client = new Client({customLogger: logx, explicitSocketBind: true});
This will bind sockets to a specific address instead of 0.0.0.0
. Please try this and let me know the results!
Thanks for the answer!
The 'explicitSocketBind' unfortunetaly does not change anything. I have tried this before too.
When i try this one for testing.
this.ssdpClient = new SsdpClient({explicitSocketBind: true, reuseAddr: true, ssdpIp: '10.0.0.4'});
i get an exception
addMembership is not defined
I will investigate further. Thank you for your help, i think we may close the issue for now. Maybe I'll come back later if i need more help or if i found a solution without disableing the SSDPSRV
I investigated further and its a little bit crazy...
The upnp lib i am using in c++ binds the ssdp ip directly and gets the SSDP events very smoothly. The node binds on 0.0.0.0 and gets the events delayed.
iIt's the same if i am subscribing to device services. In node they are delayd. Sometimes a view seconds and sometimes it goes up to 60 seconds. I think i have to dig deeper in the nodeJs server/client stuff
EDIT: And in fact it has to be a problem outside of this library. I created a really simple example for sending the M-SEARCH and as wireshark says it will never hit any interface .
Sample:
'strict'
var dgram = require('dgram');
var message = new Buffer(
"M-SEARCH * HTTP/1.1\r\n" +
"HOST:239.255.255.250:1900\r\n" +
"MAN:\"ssdp:discover\"\r\n" +
"ST:urn:schemas-upnp-org:device:MediaRenderer:1\r\n" + // Essential, used by the client to specify what they want to discover, eg 'ST:ge:fridge'
"MX:1\r\n" + // 1 second to respond (but they all respond immediately?)
"\r\n"
);
var client = dgram.createSocket("udp4");
client.on('message', function (chunk, info) {
var mes = chunk.toString();
console.log('[incoming] UDP message');
console.log(info.address);
});
client.bind(function()
{
client.send(message, 0, message.length, 1900, "239.255.255.250", function(_err)
{
console.log("Message sent: " + _err);
}
);
}
);
function execute(){
}
setInterval(execute,1000);
if i change the code (the binding) to this
client.bind(0, "10.0.0.4", function()
{
client.send(message, 0, message.length, 1900, "239.255.255.250", function(_err)
{
console.log("Message sent: " + _err);
}
);
}
);
it works always.
But either way... It seems not to be a problem within this lib so we may close this issue!
Thanks!
Hmm, you're saying that it works if you bind your listener to a specific IP address?
I think you might've found a bug. Currently, when sockets are bound they're bound to port 1900
โ https://github.com/diversario/node-ssdp/blob/master/lib/index.js#L247-L249 โ I think that might be wrong and they should be instead bound to a random port (0
).
Could you try something? Could you modify those lines I linked to to be
socket.bind(0, iface, next)
} else {
socket.bind(next) // socket binds on 0.0.0.0
Could you try something? Could you modify those lines I linked to to be
Looks way better!
Even with activated Windows SSDP service!
But in fact one media server is not always found.. I have to check this but this should be another problem
Oh, nice! Sounds like I should be making a bugfix release.
@ChriD v3.2.0 is out ๐
Thank you! very nice!
No, thank you for doing all this fantastic investigative work ๐! Very much appreciated!