MoneyBall
MoneyBall

Reputation: 2573

In python websocket client, why should the ping_interval be greater than ping_timeout

I don't understand why ping interval should be greater than ping timeout. In the websocket code found here, it defines

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.

but the code says:

if ping_timeout and ping_interval and ping_interval <= ping_timeout:
    raise WebSocketException("Ensure ping_interval > ping_timeout")

If ping_interval is greater than ping_timeout, wouldn't this cause the connection to timeout permanently?

Assume that ping_interval is greater than ping_timeout, then as long as I get a response from the server within ping_timeout, it's fine. However, why is it necessary for ping_interval to be greater than ping_timeout?

Upvotes: 2

Views: 2826

Answers (1)

petre
petre

Reputation: 1553

I expect it's because the "ping"s are not expected to be sent out before the previous one got a reply or timed out.

For example you send a ping at time t, and wait for t+ping_timeout for a reply. If ping_interval <= ping_timeout, you'd have to send out a second ping at t+ping_interval, before t+ping_timeout, and manage many pings in parallel.

Upvotes: 1

Related Questions