def read_packet(self, max_delay_time=1): """ Wait for packet from server. """ read, write, error = select.select([self.socket], [], [], max_delay_time) if not read: if time.time() - self.packet_last_sent_timestamp > 60: self.send_packet(Ping("tyrbot_aochat")) return None else: # Read data from server head = self.read_bytes(4) packet_type, packet_length = struct.unpack(">2H", head) data = self.read_bytes(packet_length) try: return ServerPacket.get_instance(packet_type, data) except Exception as e: self.logger.error( "Error parsing packet parameters for packet_type '%d' and payload: %s" % (packet_type, data), e) return None
def read_packet(self, max_delay_time=1): self.check_outgoing_message_queue() packet = super().read_packet(max_delay_time) if not packet: time_since = time.time() - self.packet_last_received_timestamp if time_since > 90: self.logger.error(f"no packet received in 90 seconds for conn {self.id}") self.failure_callback() elif time_since > 60: self.send_packet(Ping("tyrbot_aochat")) else: self.packet_last_received_timestamp = time.time() return packet