这是一些用于设置多播接收器的 Python 代码。它在 mac 和 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)
但在 Windows 上运行时在绑定上收到错误 10049。
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
Windows 多播是否存在已知问题?如果不是,我可以采取哪些步骤来诊断?