Here's some Python code to set up a multicast receiver. It works fine on mac and linux.
import socket, struct
ADDR='239.239.250.1'
PORT=8001
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.bind((ADDR, PORT))
mreq = struct.pack("4sl", socket.inet_aton(ADDR), socket.INADDR_ANY)
sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq)
but receives an error 10049 on the bind when run on windows.
Z:\winx>c:\Python27\python.exe q2.py
Traceback (most recent call last):
File "q2.py", line 11, in <module>
sock.bind((ADDR,PORT))
File "c:\Python27\lib\socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
socket.error: [Errno 10049] The requested address is not valid in its context
Is there a known problem with windows multicast? If not, what steps can I take to diagnose?
I have the same problem, and from here I understood that you need to bind to local host.
sock.bind(('', PORT))
worked for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With