def init_socket(self):
ok = True
self.ip = '239.255.255.250'
self.port = 1900
try:
#This is needed to join a multicast group
self.mreq = struct.pack("4sl",socket.inet_aton(self.ip),socket.INADDR_ANY)
#Set up server socket
self.ssock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM,socket.IPPROTO_UDP)
self.ssock.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
try:
self.ssock.bind(('',self.port))
except Exception, e:
dbg("WARNING: Failed to bind %s:%d: %s" , (self.ip,self.port,e))
ok = False
try:
self.ssock.setsockopt(socket.IPPROTO_IP,socket.IP_ADD_MEMBERSHIP,self.mreq)
except Exception, e:
dbg('WARNING: Failed to join multicast group:',e)
ok = False
except Exception, e:
dbg("Failed to initialize UPnP sockets:",e)
return False
if ok:
dbg("Listening for UPnP broadcasts")
评论列表
文章目录