ping package - librespeed/speedtest-android GitHub Wiki
Pinger
class
A Thread that uses a Connection to repeatedly ping a specified path.
A ping is defined as the time difference between the moment in which we finish sending the HTTP request, and the moment in which we start receiving the response, over a persistent HTTP connection.
Constructor:
public Pinger(Connection c, String path)
c
: the instance of Connection to be usedpath
: path on the server where the ping should be done
Callbacks:
boolean onPong(long ns)
: called after a ping.ns
is the ping time in nanoseconds. Return true to perform another ping, false to stop.onError(String err)
: called if something goes wrong.err
contains the error message
Methods:
stopASAP()
: stops the pinging as soon as possible. Usejoin()
to wait for the thread to die
PingStream
class
A stream for the ping+jitter test. Manages a Connection and a Pinger, and handles errors according to the specified policy.
Constructor:
public DownloadStream(String server, String path, int pings, String errorHandlingMode, int connectTimeout, int soTimeout, int recvBuffer, int sendBuffer, Logger log)
server
: URL to the server where we need to connectpath
: path on the server where the ping can be donepings
: number of pings to be performederrorHandlingMode
: what we should do in case of errors:SpeedtestConfig.ONERROR_FAIL
: Fail immediatelySpeedtestConfig.ONERROR_ATTEMPT_RESTART
: Try to reconnect. If that fails, the stream failsSpeedtestConfig.ONERROR_MUST_RESTART
: Keep trying to reconnect until we succeed (or stopped)
connectTimeout
,soTimeout
,recvBuffer
,sendBuffer
: settings for the socket created by Connectionlog
: instance of Logger that is used to report errors such as dead connections
Callbacks:
boolean onPong(long ns)
: called after a ping.ns
is the ping time in nanoseconds. Return true to perform another ping, false to stop.onError(String err)
: called if the stream fails.err
contains the error messageonDone()
: called after all the pings are done
Methods:
stopASAP()
: asks to stop the pinging as soon as possible. The Connection will also be closed. Usejoin()
to wait for the connection to be actually closedjoin()
: waits for the instance of Pinger to die