def pong(self, msg): """Receives pong from the server and actually calculates the offset. :param msg: The pong message :type msg: :class:`network.message.Message` """ now = tstamp(0) sent_at = self._syncing.pop(msg.data[MF.id]) self.delta = (now - msg.data[MF.timestamp] + (now - sent_at) / 2) LOG.info('Synced time with server: delta={}'.format(self.delta))
def pong(self, msg): """Receives pong from the server and actually calculates the offset. :param msg: The pong message :type msg: :class:`network.message.Message` """ now = tstamp(0) sent_at = self._syncing.pop(msg.data[MF.id]) self.delta = now - msg.data[MF.timestamp] + (now - sent_at) / 2 LOG.info("Synced time with server: delta={}".format(self.delta))
def ping(self): """Pings the server to start te timing offset calculation. """ LOG.debug('Sending ping') # Create and enqueue the ping message sync_id = next(self.sync_counter) msg = Message(MT.ping, {MF.id: sync_id, MF.timestamp: tstamp()}) def callback(): self._syncing[sync_id] = tstamp() self.proxy.enqueue(msg, callback)
def dt(self): """Returns the dt from the last update. NOTE: this method updates the internal status of the client. :returns: The dt from the last update in seconds :rtype: float """ now = tstamp() if self.last_update is None: self.last_update = now dt = (now - self.last_update) / 1000.0 self.last_update = now return dt
def callback(): self._syncing[sync_id] = tstamp()