Home   Archive   Permalink



read multicast

Hi Nick
    
I see you've contributed a new UDP scripts. Do you have an example for rebol2 on how to read messages from the multicast address of 235.255.255.250:1900?
    
I want to able to respond to SEARCH requests from Amazon's echo so I can pretend to be a Phillips Hue Bridge.
    
IF we can get it working, we can look at getting UDP multicasting working as well.

posted by:   Graham       3-Feb-2017/5:52:24-8:00



That wasn't very literate. I'd like to see if we have a working example on Rebol2 so we can then implement this on Rebol3. Ta.

posted by:   Graham       3-Feb-2017/5:53:42-8:00



Hi Graham,
    
If you are able to connect to the segment 235.255.255.250:1900 on your network, and the device there is sending UDP multicast messages:
    
net-in: open udp://:1900 ; This is UDP, so IP address isn't required
gui: view/new layout [a1: area wrap]
forever [
     received: wait [net-in]
     if not viewed? gui [quit]
     insert (at a1/text 1) copy received show a1
]

posted by:   Nick       3-Feb-2017/11:22:08-8:00



to broadcast (as 'server'):
    
net-out: open/lines udp://235.255.255.250:1900
set-modes net-out [broadcast: on]
gui: view/new layout [
     f1: field
     k1: at 0x0 key #"^M" [
         if f1/text = "" [return]
         insert net-out rejoin [name ": " f1/text]
     ]
]
forever [focus f1 wait .1]

posted by:   Nick       3-Feb-2017/11:34:01-8:00



Hi Nick
    
That doesn't work for me. I hear nothing being broadcast unless I send a SEARCH command. I then ask another device on the network to send SEARCH commands but I am not seeing them.
    
I note you don't the set-modes on multicast-groups ...
    
R E B O L [
    
]
    
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 ; udp broadcast port
set-modes odata [multicast-ttl: 10]
set-modes odata [broadcast: on]
; set-modes odata compose/deep [multicast-interface: (local-ip)]
set-modes odata compose/deep [multicast-groups: [[239.255.255.250 (local-ip)]]]
idata: none ; open udp://:1900
    
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]
         probe data: copy port
     ]

posted by:   Graham       3-Feb-2017/14:07:30-8:00



Nick, I've just realised your code is for UDP broadcast and not multicast. For multicast one needs to join the multicast group.

posted by:   Graham       3-Feb-2017/16:38:40-8:00



Sorry, different meanings of the word 'multicast'. I have no experience with IP multicast.

posted by:   Nick       4-Feb-2017/9:46:47-8:00



Ok, got it going. I had a couple of errors in the code I posted. This sends a search message to all devices in the SSDP multicast group and looks at their replies. If there's a search command, it looks at which device is sending it so it can reply if it wants to do so.
    
R E B O L [
     Notes: {to listen for SSDP messages}
     Author: "Graham"
     Date: 5-Feb-2017    
]
        
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 ; udp broadcast port
set-modes odata [multicast-ttl: 10]
; set-modes odata [broadcast: on]
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 "Multicast search issued from:"
         print [ "Address: " port/remote-ip]
         print [ "On port: " port/remote-port]
     ]
     probe data
]


posted by:   Graham       4-Feb-2017/17:18:57-8:00



I'd love to know when this gets up and running in R3.

posted by:   Nick       4-Feb-2017/21:29:38-8:00



At present there's no support for multicast or broadcast. I've asked for this to be implemented but I don't think it's high on anyone's agenda yet.
    
The reason I'm interested is so I can control things in my house using Amazon echo.

posted by:   Graham       5-Feb-2017/23:43:57-8:00



If anyone knows how to get a hold of Cyphre, I'd like to see if he's interest in completing the R3 ports and improvements we discussed last year.

posted by:   Nick       6-Feb-2017/6:58:45-8:00



If anyone knows how to reach Robert, he may know how to contact Cyphre.

posted by:   Nick       6-Feb-2017/7:06:21-8:00