websocket handler
我的aiohttp 项目中有以下内容:
async def websocket_handler(request):
ws = web.WebSocketResponse()
await ws.prepare(request)
request.app['websockets'].append(ws)
async for msg in ws:
if msg.type == aiohttp.WSMsgType.TEXT:
if msg.data == 'close':
await ws.close()
elif msg.type == aiohttp.WSMsgType.ERROR:
logger.info('ws connection closed with exception %s' %
ws.exception())
request.app['websockets'].remove(ws)
return ws
但现在我想切换到sanic
框架。如何重写这个方法?我不明白如何从本教程中做到这一点