#How to find the multicast address on Windows: #C:\> netsh interface ip show joins #on Linux: #$ ip maddr show import socket import struct import sys PORT=10000 multicast_group = '224.3.29.71' server_address = ('', PORT) # 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) # Receive/respond loop while True: print ('\nwaiting to receive message on ',multicast_group, PORT) data, address = sock.recvfrom(1024) print('received %s bytes from %s' % (len(data), address)) print(data) print ('sending acknowledgement to', address) sock.sendto(data, address)