websocket_connections.py 文件源码

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

项目:monitor 作者: ReCodEx 项目源码 文件源码
def __init__(self, websock_uri, connections, loop, logger):
        """
        Initialize new instance

        :param websock_uri: Tuple containing hostname and port for websocket server
        :param connections: Reference to ClientConnections class through which are
            sent messages from other threads. Note, that this must be invoked thread
            safe via given message loop of asyncio module.
        :param loop: Asyncio message loop for handling connections
        :param logger: System logger instance
        """
        super().__init__()
        self._connections = connections
        self._loop = loop
        self._logger = logger
        hostname, port = websock_uri
        asyncio.set_event_loop(loop)
        start_server = websockets.serve(self.connection_handler, hostname, port)
        loop.run_until_complete(start_server)
        self._logger.info("websocket server initialized at {}:{}".format(hostname, port))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号