Ejemplo n.º 1
0
 def status(self, retries=3, **kwargs):
     exception = None
     for attempt in range(retries):
         try:
             connection = TCPSocketConnection((self.host, self.port))
             pinger = ServerPinger(connection,
                                   host=self.host,
                                   port=self.port,
                                   **kwargs)
             pinger.handshake()
             result = pinger.read_status()
             try:
                 result.latency = pinger.test_ping()
             except IOError:
                 # Some servers have an animated MOTD, which is nonstandard and
                 # breaks the protocol. We don't get latency for these servers.
                 result.latency = 0.00
             return result
         except Exception as e:
             exception = e
         finally:
             try:
                 connection.close()
             except:
                 pass
     else:
         raise exception
Ejemplo n.º 2
0
    def status(self, tries: int = 3, **kwargs):
        """Checks the status of a Minecraft Java Edition server via the ping protocol.

        :param int tries: How many times to retry if it fails.
        :param type **kwargs: Passed to a `ServerPinger` instance.
        :return: Status information in a `PingResponse` instance.
        :rtype: PingResponse
        """

        connection = TCPSocketConnection((self.host, self.port))
        exception = None
        for attempt in range(tries):
            try:
                pinger = ServerPinger(connection,
                                      host=self.host,
                                      port=self.port,
                                      **kwargs)
                pinger.handshake()
                result = pinger.read_status()
                result.latency = pinger.test_ping()
                return result
            except Exception as e:
                exception = e
        else:
            raise exception
Ejemplo n.º 3
0
 def ping(self, retries=3, **kwargs):
     connection = TCPSocketConnection((self.host, self.port))
     exception = None
     for attempt in range(retries):
         try:
             pinger = ServerPinger(connection, host=self.host, port=self.port, **kwargs)
             pinger.handshake()
             return pinger.test_ping()
         except Exception as e:
             exception = e
     else:
         raise exception
Ejemplo n.º 4
0
 def status(self, tries=3, **kwargs):
     connection = TCPSocketConnection((self.host, self.port))
     exception = None
     for attempt in range(tries):
         try:
             pinger = ServerPinger(connection, host=self.host, port=self.port, **kwargs)
             pinger.handshake()
             result = pinger.read_status()
             result.latency = pinger.test_ping()
             return result
         except Exception as e:
             exception = e
     else:
         raise exception
Ejemplo n.º 5
0
 def status(self, retries=3, timeout=None, **kwargs):
     connection = TCPSocketConnection((self.host, self.port),
                                      timeout=timeout)
     exception = None
     for attempt in range(retries):
         try:
             pinger = ServerPinger(connection,
                                   host=self.host,
                                   port=self.port,
                                   **kwargs)
             pinger.handshake()
             result = pinger.read_status()
             result.latency = pinger.test_ping()
             return result
         except Exception:
             if attempt == retries - 1:
                 raise
Ejemplo n.º 6
0
    def ping(self, tries: int = 3, **kwargs):
        """Checks the latency between a Minecraft Java Edition server and the client (you).

        :param int tries: How many times to retry if it fails.
        :param type **kwargs: Passed to a `ServerPinger` instance.
        :return: The latency between the Minecraft Server and you.
        :rtype: float
        """

        connection = TCPSocketConnection((self.host, self.port))
        exception = None
        for attempt in range(tries):
            try:
                pinger = ServerPinger(connection, host=self.host, port=self.port, **kwargs)
                pinger.handshake()
                return pinger.test_ping()
            except Exception as e:
                exception = e
        else:
            raise exception
Ejemplo n.º 7
0
 def setUp(self):
     self.pinger = ServerPinger(Connection(),
                                host="localhost",
                                port=25565,
                                version=44)