2005年11月29日 星期二 11:35
在window下 .... mcast_ip = '224.0.0.33' port = 5333 data = struct.pack('!IIII', 0, 0, 0, 0) s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.bind((local_ip, port)) s.sendto(data, 0, (mcast_ip, port)) mreq = socket.inet_aton(mcast_ip) + socket.inet_aton(local_ip) s.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq) s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) s.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_LOOP, 0); s.settimeout(timeout) 可以正常运行 在solaris下: if ( os.name == 'posix' ): print 'Unix System Socket' s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM) #s.bind((local_ip, port)) #这句报错,察看帮助,Unixt下的Python不支持 绑定 port s.sendto(data,0,(mcast_ip,port)) mreq = socket.inet_aton(mcast_ip) + socket.inet_aton(local_ip) s.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq) s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) #s.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_LOOP, 0) #这句报错 else: 。。。 s.settimeout(timeout) 察看帮助 http://docs.python.org/lib/socket-objects.html *setsockopt*( level, optname, value) Set the value of the given socket option (see the Unix manual page *setsockopt*(2)). The needed symbolic constants are defined in the socket module (SO_* etc.). The value can be an integer or a string representing a buffer. In the latter case it is up to the caller to ensure that the string contains the proper bits (see the optional built-in module struct<http://docs.python.org/lib/module-struct.html>for a way to encode C structures as strings). 一直没有找到 这个 Unix manual page ,有谁知道在哪可以察看, 或者有谁有 在Unix下使用python发送多播包的经验? thanks~~~ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20051129/cf7e1394/attachment.htm
Zeuux © 2025
京ICP备05028076号