def handle(request):
peername = request.transport.get_extra_info('peername')
host = port = "unknown"
if peername is not None:
host, port = peername[0:2]
log.debug("web resource socket request from {}[{}]".format(host, port))
ws = web.WebSocketResponse()
await ws.prepare(request)
jh = ResourceHandler(ws)
async for msg in ws:
if msg.type == aiohttp.WSMsgType.TEXT:
if msg.data == 'close':
await ws.close()
await jh.shutdown()
return ws
elif msg.data == 'start-cpu-utilization':
jh.sync_cpu_usage()
elif msg.data == 'start-process-utilization':
jh.sync_process_utilization()
elif msg.data == 'get-meminfo':
jh.get_meminfo()
else:
log.debug("unknown websocket command: {}".format(msg.data))
elif msg.type == aiohttp.WSMsgType.ERROR:
print('ws connection closed with exception %s' % ws.exception())
return ws
评论列表
文章目录