socketio 客户端成功连接到服务器并向emit服务器发送消息,但向客户端的另一个方向服务器失败。我找不到错误的根源。这是
这是基于python-socketioapp.py网站中的示例的服务器 python :
from aiohttp import web\nimport socketio\n\nsio = socketio.AsyncServer()\napp = web.Application()\nsio.attach(app)\n\nasync def index(request):\n """Serve the client-side application."""\n with open(\'index.html\') as f:\n return web.Response(text=f.read(), content_type=\'text/html\')\n\n@sio.on(\'connect\', namespace=\'/chat\')\ndef connect(sid, environ):\n print("connect", sid)\n\n@sio.on(\'chat message\', namespace=\'/chat\')\nasync def message(sid, data):\n print("server received message!", data)\n await sio.emit(\'reply\', data)\n await sio.send(data)\n\n@sio.on(\'disconnect\', namespace=\'/chat\')\ndef disconnect(sid):\n print(\'disconnect\', sid)\n\napp.router.add_static(\'/static\', \'static\')\napp.router.add_get(\'/\', index)\n\nif __name__ == \'__main__\':\n web.run_app(app)\nRun Code Online (Sandbox Code Playgroud)\n\n我尝试评论其中之一await sio.emit(\'reply\', data)或await sio.send(data)但结果是相同的。这是 javascript 客户端index.html:
<html>\n <head>\n <script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/1.3.5/socket.io.min.js"></script>\n …Run Code Online (Sandbox Code Playgroud)