在 python websocket 客户端中,为什么 ping_interval 应该大于 ping_timeout
In python websocket client, why should the ping_interval be greater than ping_timeout
我不明白为什么 ping 间隔应该大于 ping 超时。在找到的 websocket 代码中 here,它定义了
ping_interval: automatically send "ping" command every specified period(second) if set to 0, not send automatically.
ping_timeout: timeout(second) if the pong message is not received.
但是代码说:
if ping_timeout and ping_interval and ping_interval <= ping_timeout:
raise WebSocketException("Ensure ping_interval > ping_timeout")
如果ping_interval
大于ping_timeout
,这不会导致连接永久超时吗?
假设ping_interval
大于ping_timeout
,那么我只要在ping_timeout
之内得到服务器的响应就可以了。但是,为什么需要让ping_interval
大于ping_timeout
呢?
我预计这是因为 "ping" 预计不会在前一个收到回复或超时之前发送出去。
例如,您在时间 t 发送 ping,然后等待 t+ping_timeout
回复。如果 ping_interval <= ping_timeout
,您必须在 t+ping_timeout
之前在 t+ping_interval
发送第二个 ping,并并行管理许多 ping。
我不明白为什么 ping 间隔应该大于 ping 超时。在找到的 websocket 代码中 here,它定义了
ping_interval: automatically send "ping" command every specified period(second) if set to 0, not send automatically.
ping_timeout: timeout(second) if the pong message is not received.
但是代码说:
if ping_timeout and ping_interval and ping_interval <= ping_timeout:
raise WebSocketException("Ensure ping_interval > ping_timeout")
如果ping_interval
大于ping_timeout
,这不会导致连接永久超时吗?
假设ping_interval
大于ping_timeout
,那么我只要在ping_timeout
之内得到服务器的响应就可以了。但是,为什么需要让ping_interval
大于ping_timeout
呢?
我预计这是因为 "ping" 预计不会在前一个收到回复或超时之前发送出去。
例如,您在时间 t 发送 ping,然后等待 t+ping_timeout
回复。如果 ping_interval <= ping_timeout
,您必须在 t+ping_timeout
之前在 t+ping_interval
发送第二个 ping,并并行管理许多 ping。