def _ws_loop(self):
"""Run the websocket loop listening for messages."""
msg = None
try:
while True:
msg = yield from self._ws_connection.receive()
if msg.type == aiohttp.WSMsgType.TEXT:
self._handle_packet(msg.data)
elif msg.type == aiohttp.WSMsgType.CLOSED:
break
elif msg.type == aiohttp.WSMsgType.ERROR:
break
except (ClientError, HttpProcessingError, asyncio.TimeoutError) as exc:
raise exceptions.TransportError from exc
finally:
yield from self.ws_close()
self._handle_event(EVENT_WS_CLOSED, None)
if msg is not None and msg.type == aiohttp.WSMsgType.ERROR:
raise exceptions.TransportError(
'Websocket error detected. Connection closed.')
评论列表
文章目录