除非我弄错了,否则这不是一个很重复的东西。我不是使用Tornado,我只想每隔30秒发送一个ping帧,以使用websockets库保持连接。在
作为一个冒险者,我有一个猜测,但我不知道如何理解服务器回复:
import websockets
import asyncio
async def test_ping():
websocket = await websockets.connect('wss://api.example.com')
reply = await websocket.ping()
print(reply)
loop = asyncio.new_event_loop()
loop.create_task(test_ping())
loop.run_forever()
>> <Future pending>
(我已经建立了一个连接以生成“未来待定”响应。)
如果客户机和服务器都使用同一个库,PING和PONG帧不会自动发送,当一方要检查另一方是否在线时,它通过调用用户的PING()方法发送PING帧,另一方通过内部调用PONG()方法自动回复PING帧,所以我们不需要关心传入的PING我们自己帧并调用pong()。(可以将pong()看作一个私有函数。)
{a1}
相关问题 更多 >
编程相关推荐