Close

Keepalive algorithm

A project log for HTTaP

Test Access Port over HTTP

yann-guidon-ygdesYann Guidon / YGDES 05/04/2020 at 00:430 Comments

The latest version of the server implements the new /?ping key that returns the time until connection timeout.

This makes the client's algorithm very simple : send a /?ping, receive the number, subtract 2 or 3 to have some margin, and wait during so many seconds before sending another ping. If the client sends a new request before, cancel the timer then reload it with the last result.

Easy, right ? At least it shouldn't make you sweat a bit in JavaScript.

The granularity of the value is quite coarse due to so many sources of jitter so 2 or 3 seconds of margin should work... Unless the server's workload is more than one second per poll. But in this case, the server will check for a new packet before eventually closing the socket so don't be afraid. The 3 seconds margin would be eaten up in case of severe network degradation... which shouldn't happen in a local network, right ?

Discussions