Add a client implementation
This commit is contained in:
parent
c9a71da411
commit
5584b459cd
|
@ -0,0 +1,19 @@
|
|||
import socket
|
||||
import struct
|
||||
|
||||
multicast_address = '224.0.0.251'
|
||||
multicast_port = 5353
|
||||
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
sock.bind(('', multicast_port))
|
||||
|
||||
group = socket.inet_aton(multicast_address)
|
||||
mreq = struct.pack('4sL', group, socket.INADDR_ANY)
|
||||
sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq)
|
||||
|
||||
print(f"Listening for messages on {multicast_address}:{multicast_port}")
|
||||
|
||||
while True:
|
||||
data, addr = sock.recvfrom(1024)
|
||||
print(f"Received message: {data.decode()} from {addr}")
|
Loading…
Reference in New Issue