python websocket server在收到接受消息处理完后会默认关闭连接。需要在msg_handler里面加个while true就能一直保持连接了。
start_server = websockets.serve(msg_handler, "0.0.0.0", 29967)
asyncio.get_event_loop().run_until_complete(start_server)
asyncio.get_event_loop().run_forever()
async def msg_handler(websocket, path):
while True:
data = await websocket.recv()
//do someting
await websocket.send('hey')