def api(ws, path):
while True:
try:
# msg = await ws.recv()
# get a websockets string
msg = yield from ws.recv()
print('msg', msg)
try:
msgJ = json.loads(msg)
except json.decoder.JSONDecodeError:
print("error decoding msg >{}<".format(msg))
continue
print("got json msgJ >{}<".format(msgJ))
# and handle it...
retJ = handleMsg(msgJ)
#print(retJ)
# and return the response to the client
yield from ws.send(retJ)
# await ws.send(retJ)
except websockets.ConnectionClosed:
print('connection closed')
return
评论列表
文章目录