async def relayHandler(request):
print('Websocket connection starting')
ws = aiohttp.web.WebSocketResponse(autoclose=True)
await ws.prepare(request)
print('Websocket connection ready')
async for msg in ws:
print(msg)
if msg.type == aiohttp.WSMsgType.TEXT:
print(msg.data)
if msg.data == 'close':
await ws.close()
else:
await ws.send_str(msg.data + '/answer')
elif msg.type == aiohttp.WSMsgType.ERROR:
print('ws connection closed with exception %s' %ws.exception())
print('Websocket connection closed')
return ws
this is my websocket handler it uses aiohttp on top of asyncio. The problem is if i disconnect the clients wifi connection its not detecting that the connection is lost. i also tried using the Websockets module, but the same thing happend. But when the client is on localhost then working perfectly. Whats the main reason for this, and if anyone could explain how to properly catch network exceptions inside asyncio.