protected void tick ( ) { // if we're not connected, skip it if ( _comm == null ) { return ; } long now = RunAnywhere . currentTimeMillis ( ) ; if ( _dcalc != null ) { // if our current calculator is done, clear it out if ( _dcalc . isDone ( ) ) { if ( debugLogMessages ( ) ) { log . info ( "Time offset from server: " + _serverDelta + "ms." ) ; } _dcalc = null ; } else if ( _dcalc . shouldSendPing ( ) ) { // otherwise, send another ping PingRequest req = new PingRequest ( ) ; _comm . postMessage ( req ) ; _dcalc . sentPing ( req ) ; } } else if ( now - _comm . getLastWrite ( ) > PingRequest . PING_INTERVAL ) { // if we haven't sent anything over the network in a while, we ping the server to let // it know that we're still alive _comm . postMessage ( new PingRequest ( ) ) ; } else if ( now - _lastSync > CLOCK_SYNC_INTERVAL ) { // resync our clock with the server establishClockDelta ( now ) ; } }
Called every five seconds ; ensures that we ping the server if we haven t communicated in a long while and periodically resyncs the client and server clock deltas .