-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_client.py
More file actions
28 lines (22 loc) · 766 Bytes
/
Copy pathrun_client.py
File metadata and controls
28 lines (22 loc) · 766 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import socket
import struct
import sys
multicast_group = '224.3.29.71'
server_address = ('', 10000)
# Create the socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# Bind to the server address
sock.bind(server_address)
# Tell the operating system to add the socket to the multicast group
# on all interfaces.
group = socket.inet_aton(multicast_group)
mreq = struct.pack('4sL', group, socket.INADDR_ANY)
sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq)
while True:
print("waiting")
data, address = sock.recvfrom(1024)
msg = bytes.decode(data)
print("Message: " + msg + "\n")
print("Address:" + address[0] + "\t From Port: " + str(address[1]))
print("sending reply")
sock.sendto("ack".encode(), address)