connections set async def websocket_handler request ws web WebSocketRe

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
connections = set()
async def websocket_handler(request):
ws = web.WebSocketResponse()
await ws.prepare(request)
async for msg in ws:
if msg.type == WSMsgType.TEXT:
connections.add(ws)
await ws.send_str('answer')
connections.remove(ws)
return ws