[Gambas-user] HowTo a M-Search (UPnP)

Ingo bm.530502 at gmail.com
Mon Oct 30 19:39:28 CET 2017


Am 29.10.2017 um 20:10 schrieb Tobias Boege:
> On Sun, 29 Oct 2017, Ingo wrote:
>> Am 29.10.2017 um 18:39 schrieb Tobias Boege:
>>> I can't answer your question about HttpClient without looking into the
>>> curl source code (maybe they support an "httpu://" schema, but I wouldn't
>>> bet on it).
>> Yes, that's maybe true. I have not found an example anywhere with curl?!
>>
>>> The key to the warnings you get would be your(?) upnp.txt file which
>>> is read by "curl -K", yes? The warnings about trailing garbage could
>>> come from a wrong EOL marker in that file. If HTTPU is like HTTP in
>>> that regard, it will use the "windows" EOL sequence "\r\n".
>> I know about the CRLF. Even the last line has one. I've tried it with \n\r,
>> \r\n and gb.CrLf.
>>> I would just use the UdpSocket from gb.net to send these requests.
>> Hi Tobi,
>> thanks for your reply. Do you have an approach with udpsocket?
>>
> See the attached script. The UdpSocket interface looks a little weird
> with the manual Watch method. I don't think I've used it before, and
> I don't know if the script is working, as I get no response on the
> network here, but at least the code throws no error.
>
> Regards,
> Tobi
>
>
Hello Tobias,
here is the full solution doing a M-Search based on your approach:

Public Sub btnM_Search_Click()
Dim sMSearch As String
   $hUdp = New UdpSocket As "Socket"
   $hUdp.Broadcast = True
   $hUdp.Timeout = 500
   $hUdp.EndOfLine = gb.Windows
   $hUdp.Bind()

   sMSearch = "M-SEARCH * HTTP/1.1\r\n"
   sMSearch &= "HOST: 239.255.255.250:1900\r\n"
   sMSearch &= "MAN: \"ssdp:discover\"\r\n"
   sMSearch &= "MX: 3\r\n"
   sMSearch &= "ST: ssdp:all\r\n\r\n"
   'sMSearch &= "ST: urn:schemas-upnp-org:device:MediaRenderer:1\r\n\r\n"

   $hUdp.TargetHost = "239.255.255.250"
   $hUdp.TargetPort = 1900
   Write #$hUdp, sMSearch
   Debug "Request sent"
End

Public Sub Socket_Read()
   Dim sMsg As String

   While Not Eof($hUdp)
     Read #$hUdp, sMsg, Lof($hUdp)
   Wend

   Debug sMsg
End

Public Sub Socket_Error()
   Debug "Error?"
End

The problem that not all devices were shown were the missing quotes in 
"MAN: \"ssdp:discover\"\r\n".
I did an analysis with wireshark and saw the quotes when I used 
gssdp-discover.

Now it should work as expected. Could you test it?

Thanks an regards
Ingo



More information about the User mailing list