public boolean gotPong ( PongResponse pong ) { if ( _ping == null ) { // an errant pong that is likely being processed late after // a new connection was opened. return false ; } // don't freak out if they keep calling gotPong() after we're done if ( _iter >= _deltas . length ) { return true ; } // make a note of when the ping message was sent and when the pong // response was received (both in client time) long send = _ping . getPackStamp ( ) , recv = pong . getUnpackStamp ( ) ; _ping = null ; // clear out the saved sent ping // make a note of when the pong response was sent (in server time) // and the processing delay incurred on the server long server = pong . getPackStamp ( ) , delay = pong . getProcessDelay ( ) ; // compute the network delay (round-trip time divided by two) long nettime = ( recv - send - delay ) / 2 ; // the time delta is the client time when the pong was received // minus the server's send time (plus network delay): dT = C - S _deltas [ _iter ] = recv - ( server + nettime ) ; log . debug ( "Calculated delta" , "delay" , delay , "nettime" , nettime , "delta" , _deltas [ _iter ] , "rtt" , ( recv - send ) ) ; return ( ++ _iter >= CLOCK_SYNC_PING_COUNT ) ; }
Must be called when the pong response arrives back from the server .