I am just a beginner with programming the Pronto TSU series of remotes. I am trying to understand the Pronto UDP functions so that I can perform a SSDP query to find he IP address of my Roku box. I think I know how to setup the UDP socket and send request but I don't understand how to read back the response so that I can parse if for the IP address.
I need to send the following request using http protocol to 239.255.255.250 port 1900
M-SEARCH * HTTP/1.1
Host: 239.255.255.250:1900
Man: "ssdp:discover"
ST: roku:ecp
I am doing this using the following code
var TARGETADDRESS = "239,255.255.250";
var PORT = 1900;
var aServiceType = "roku:ecp";
var reg;
var socket = new UDPSocket();
req = "M-SEARCH * HTTP/1.1\r\n";
req += "HOST: " + TARGETADDRESS + ":" + PORT + "\r\n";
req += "MAN: \"ssdp:discover\"\r\n";
req += "ST: " + aServiceType + "\r\n";
req += "\r\n";
socket.send(req, TARGETADDRESS, PORT);
I believe this is correct coding to send out the request. What I don't understand is how to get the response back into a string that I can parse to locate the IP address of my Roku. The response I am looking for is something like this
HTTP/1.1 200 OK
Cache-Control: max-age=300
ST: roku:ecp
Location:
[Link: 192.168.1.134]USN: uuid:roku:ecp:P0A070000007
With TCP sockets I would use a socket read to obtain the response, but there does not appear to be a socket read function with UDP socket. The developers guide shows the following example
var s = new UDPSocket(1900);
s.onData = function (aData, aHost, aPort) {
System.print("Received " + aData.length + " bytes");
System.print("Client IP address: " + aHost);
System.print("Client UDP port: " + aPort);
};
If I understand functions correctly aData, aHost and aPort are variables I pass into the function. I don't understand this example. How do I go about getting the data received when the Roku box response to my request. If it was a TCP socket I would do it using
var socket, aData;
socket = new TCPSocket();
socket.onData = function() {
aData = socket.read();
};
There does not appear to be an equivalent read function for UDP sockets. Can someone explain how to do it with a UDP socket. Do I need to set up the response port before I sent the request? Do I need a separate socket for the request and the response?
Thanks,
Ed