参考文章: https://blog.youkuaiyun.com/xietansheng/article/details/115558069
服务器端
import asyncio
import websockets
import asyncio
import websockets
from websockets.legacy.server import WebSocketServerProtocol
import json
import time
import threading
clients={
}
async def ws_handle(websocket: WebSocketServerProtocol, path: str):
# if(websocket in clients):
async for message in websocket:
print(message)
jsonmsg = json.loads(message)
if("deviceMac" in jsonmsg):
mac = jsonmsg["deviceMac"]
if(mac not in clients):
clients[mac] = websocket
await websocket.send(message)
async def sendmsg(mac,mssage

最低0.47元/天 解锁文章
1771





