You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import net
import multicast
const
HELLO_PORT =1900
HELLO_GROUP ="239.255.255.250"# router discovery
MSG_LEN =1024var
data: string=""
address: string=""
port: Port
var socket = newSocket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)
socket.setSockOpt(OptReuseAddr, true)
socket.bindAddr(Port(HELLO_PORT))
ifnot socket.joinGroup(HELLO_GROUP):
echo "could not join multicast group"
quit()
socket.enableBroadcast true
echo "enabled broadcast for the socket, this is not needet for multicast only!"# For testing we speak upnp manuallyvar disc ="""M-SEARCH * HTTP/1.1Host:239.255.255.250:1900ST:urn:schemas-upnp-org:device:InternetGatewayDevice:1Man:"ssdp:discover"MX:3"""&"\c\r\c\r"# Socket is still a "normal" socket.# To send to the multicast group just send to its address# Sending sockets does not have to be in the multicast groupdiscard socket.sendTo(HELLO_GROUP, Port(HELLO_PORT), disc)
# The socket is supposed to receive every udp datagram# sent to the multicast group.whiletrue:
echo "R: ", socket.recvFrom(data, MSG_LEN, address, port ), "", address,":", port, "" , data
# Instruct the kernel to leave the group.
assert socket.leaveGroup(HELLO_GROUP) ==true
About
procs to work with multicast groups and ip broadcast