【发布时间】:2021-08-12 09:34:13
【问题描述】:
我想发出一个本地事件,而不是使用来自服务器的事件。基本上,本地调用事件。原因是处理数据,然后可以被另一个函数使用。
相关问题:
Can the socket.io client emit events locally? - 这仅支持 node.js,不支持它的 python 实现。
代码:
await self.sio.connect(SOCKET_IP, namespaces=['/'], transports=['websocket'])
await sio.emit("connection")
await sio.emit('authentication', {'token': new_token})
@sio.event
async def auth_err(data):
authErr = True
await sio.disconnect()
@sio.event
async def alive_status(data):
await sio.emit("alive_status_return", "alive")
@sio.on('connected')
async def on_connect(data):
print("Connected")
我确定sio.emit() 会广播到我不想要的服务器。
看着做sio.call(),但最终得到await sio.call("on_new_data")给Sending packet MESSAGE data 21["on_new_data"]
那么函数没有获取到数据
@sio.event
async def on_new_data():
print("2")
【问题讨论】: