def __init__(self, port, callback, bindaddress=''):
asyncore.dispatcher.__init__(self)
# self.lock = threading.RLock()
self.MAX_MTU = 1500
self.callback = None
self.port = port
if callback is not None and isinstance(callback, IUdpCallback):
self.callback = callback
else:
raise Exception('callback is None or not an instance of IUdpCallback class')
try:
self.create_socket(socket.AF_INET, socket.SOCK_DGRAM)
self.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
# self.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.set_reuse_addr()
self.bind((bindaddress, port))
except Exception as e:
print e
traceback.print_exc()
self.send_queue = Queue.Queue() # thread-safe queue
AsyncController.instance().add(self)
if self.callback is not None:
self.callback.on_started(self)
# Even though UDP is connectionless this is called when it binds to a port
评论列表
文章目录