rebol - 我如何加入 Rebol 中的 SSDP 多播组?

标签 rebol rebol2 ssdp

我正在尝试收听 SSDP 多播消息,例如 NOTIFY 和 SEARCH。

这是我的代码,但我没有看到这些消息,即使 wireshark 看到了它们。那么,如何加入SSDP多播组并接收消息呢?

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
]

最佳答案

以下代码首先发送一个SSDP SEARCH命令来接收网络上的所有设备,然后监听来自其他设备的SEARCH命令。<​​/p>

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
]

关于rebol - 我如何加入 Rebol 中的 SSDP 多播组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42034260/

相关文章:

重建 2 : Using a parse rule to check input without executing code

string - 将值保存到 block 而不是表示它的单词标签

python-3.x - SSDP M-search不适用于单播-单个IP

Rebol 3 - 阅读网站

post - 在 Red 中发出 POST 请求时如何在 header 中使用变量

conditional-statements - Rebol 的任一条件都无法正常工作

java - Android 多播地址已被使用

rebol - 为什么 Rebol 列表中 'clear' 和 'unset' 的用法存在差异?

networking - 如何处理 Rebol 3 方案中的超时时间

upnp - 发送M-SEARCH后如何持续监听SSDP响应