Hello everyone,
I am currently trying to get a list of UPnP device via SSDP (Simple Service
Discovery Protocol).
A minimalistic working NodeJS example looks like this:
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:ssdp:all\r\n" +
"MX:1\r\n" +
"\r\n"
);
var client = dgram.createSocket("udp4");
client.on("message", function (msg, rinfo) {
console.log("server got: " + msg + " from " + rinfo.address + ":" +
rinfo.port);
});
client.send(message, 0, message.length, 1900, "239.255.255.250");
client.close();
I tried to recreate the same functionality in Pharo with the following
piece of code:
| message udpSocket host |
message := 'M-SEARCH * HTTP/1.1\r\n' ,
'HOST:239.255.255.250:1900\r\n' ,
'MAN:"ssdp:discover"\r\n' ,
'ST:ssdp:all\r\n' ,
'MX:1\r\n' , '\r\n'.
udpSocket := Socket newUDP.
host := (NetNameResolver addressFromString: '239.255.255.250').
udpSocket sendData: message toHost: host port: 1900.
"udpSocket waitForData."
Transcript show: 'Received: ' , udpSocket receiveData.
udpSocket closeAndDestroy.
Unfortunately, this script hangs both in Pharo3 and Pharo4 (OS X 10.10,
Pharo 30856 and 40611).
When I interrupt with Cmd+. the debugger shows the method
Socket>>waitForDataIfClosed:
and the hang is apparently in the line
self readSemaphore wait
Could anyone give me some advice if I should to do this differently or what
the issue with the Pharo script is?
Thanks in advance,
Manfred