This commit is contained in:
qiangyanwen 2022-12-16 13:39:26 +08:00
parent 5492b22f68
commit 28fc9e0e65
1 changed files with 5 additions and 5 deletions

View File

@ -22,16 +22,16 @@ async def websocket_endpoint(
await manager.connect(websocket) await manager.connect(websocket)
logger.info("ws开始连接....") logger.info("ws开始连接....")
logger.info("websocket client ip==>{} port===>{}".format(websocket.client.host, websocket.client.port)) logger.info("websocket client ip==>{} port===>{}".format(websocket.client.host, websocket.client.port))
try:
while True:
message = {"disk_info": await get_disk_info(), "sys_info": await get_sys_info(), message = {"disk_info": await get_disk_info(), "sys_info": await get_sys_info(),
"cpu_info": await get_cpu_info(), "memory_info": await ge_mem_info()} "cpu_info": await get_cpu_info(), "memory_info": await ge_mem_info()}
try: try:
while True: await asyncio.wait_for(websocket.receive_text(), 3)
try:
data = await asyncio.wait_for(websocket.receive_text(), 3)
await manager.send_json(message, websocket) await manager.send_json(message, websocket)
except asyncio.TimeoutError: except asyncio.TimeoutError:
logger.info("开始推送数据.......") print("推送数据......", message)
await manager.send_json(message, websocket) await manager.send_json(message, websocket)
except (WebSocketDisconnect, RuntimeError,): except (WebSocketDisconnect, RuntimeError):
logger.info("ws开始关闭连接.....") logger.info("ws开始关闭连接.....")
manager.disconnect(websocket) manager.disconnect(websocket)