Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error 10049 on Windows Python Multicast

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?

like image 817
Mark Harrison Avatar asked Apr 08 '13 03:04

Mark Harrison


1 Answers

I have the same problem, and from here I understood that you need to bind to local host. sock.bind(('', PORT)) worked for me.

like image 132
Isaac Avatar answered Oct 12 '22 12:10

Isaac