Example #1
0
    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))
Example #2
0
    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))
Example #3
0
    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)
Example #4
0
    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)
Example #5
0
    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
Example #6
0
    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
Example #7
0
 def callback():
     self._syncing[sync_id] = tstamp()
Example #8
0
 def callback():
     self._syncing[sync_id] = tstamp()