asyncUdp.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:pyserver 作者: juhgiyo 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号