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))
评论列表
文章目录