yangw13
yangw13
采纳率0%
2018-10-22 11:03 阅读 2.2k

windows下用python加入指定源组播报错(10049 在其上下文中,请求的地址无效)

windows下用python加入指定源组播的时候,执行语句
s.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_SOURCE_MEMBERSHIP, imr)
报错[Errno 10049],上下文错误!

运行环境为 Win10 64bit,python2.7 python3.6 32bit/64bit

网上也参考了相关的代码,测试了多个版本都是同样的错误,望大牛指点,谢谢!

测试代码如下:

import socket
from win_inet_pton import inet_pton

if not hasattr(socket, 'IP_ADD_SOURCE_MEMBERSHIP'):
setattr(socket, 'IP_ADD_SOURCE_MEMBERSHIP', 15)

group = '239.192.70.40'
port = 40040
bind = '0.0.0.0'
source = '10.50.129.90'

s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)

imr = (socket.inet__pton(socket.AF__INET, group) + socket.inet_pton(socket.AF_INET, bind) + socket.inet_pton(socket.AF_INET, source))

s.setsockopt(socket.IPPROTO_IP, socket.SO_REUSEADDR, 1)
s.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_SOURCE_MEMBERSHIP, imr)
s.bind((group, port))

while True:
msg = s.recv(16384)
print len(msg)

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

相关推荐