def ping(self): """ Execute PING request. Send empty request and receive empty response from server. :return: response time in seconds :rtype: float """ t0 = time.time() self._socket.sendall(struct_LLL.pack(0xff00, 0, 0)) request_type, body_length, request_id = struct_LLL.unpack( self._socket.recv(12)) t1 = time.time() assert request_type == 0xff00 assert body_length == 0 return t1 - t0
def header(cls, body_length): return struct_LLL.pack(cls.request_type, body_length, 0)
def __init__(self, conn): super(RequestPing, self).__init__(conn) self._bytes = struct_LLL.pack(REQUEST_TYPE_PING, 0, 0)