7

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?

Mark Harrison
  • 297,451
  • 125
  • 333
  • 465

2 Answers2

1

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

Isaac
  • 403
  • 4
  • 5
0

I think you have wrong address, assuming that you meant something well-known, e.g. site-local multicast.

Per http://www.cisco.com/c/dam/en/us/support/docs/ip/ip-multicast/ipmlt_wp.pdf this address belongs to [possibly unused] site-local expansion.

Perhaps Windows validates the address for you?

Dima Tisnek
  • 11,241
  • 4
  • 68
  • 120