3

I'm trying to listen to SSDP multicast messages such as NOTIFY and SEARCH.

This is my code but I'm not seeing these messages even though wireshark sees them. So, how do I join the SSDP multicast group and receive messages?

Rebol []

attempt [close ssdp]
local-ip: read join dns:// read dns://

ssdp: open/binary udp://:8000
probe group: compose/deep [multicast-groups: [[235.255.255.250 (local-ip)]]]
set-modes ssdp group

forever [
    port: wait [ssdp]
    probe data: copy port
]
Graham Chiu
  • 4,856
  • 1
  • 23
  • 41
  • Isn't SSDP uses UDP port 1900? – endo64 Feb 04 '17 at 08:54
  • @endo64 Yes it does. I didn't realise that all devices have to open a server port on 1900 as well which is used to receive the multicast messages, and they use a different address to receive UDP unicast messages from other devices on the network. – Graham Chiu Feb 04 '17 at 10:12

1 Answers1

1

The following codes sends a SSDP SEARCH command first to pickup all the devices on the network, and then listens for a SEARCH command from other devices.

REBOL [ 
    Notes: {to listen for SSDP messages.  Works on Rebol2}   
] 

local-ip: read join dns:// read dns:// 

probe local-ip 

attempt [close odata] 
attempt [close idata] 

odata: open/binary udp://239.255.255.250:1900 ; SSDP multicast port address 
set-modes odata [multicast-ttl: 10]
; next line seems unnecessary
; set-modes odata compose/deep [multicast-interface: (local-ip)] 

idata: open/binary udp://:1900 
set-modes idata compose/deep [multicast-groups: [[239.255.255.250 (local-ip)]]] 

ST: "ssdp:all" 
MX: 3 

insert odata rejoin [ 
         {M-SEARCH * HTTP/1.1} crlf 
         {HOST: 239.255.255.250:1900} crlf 
         {MAN: "ssdp:discover"} crlf 
         {MX: } MX crlf 
         {ST: } ST crlf 
         crlf 
] 

forever [ 
    port: wait [odata idata] 
    data: copy port 
    if find/part data {M-SEARCH} 8 [
        print "SSDP search issued from:"
        print [ "Address: " port/remote-ip]
        print [ "On port: " port/remote-port]
    ]
    probe data
]
Graham Chiu
  • 4,856
  • 1
  • 23
  • 41