Esempio n. 1
0
    def recv(self, cmd_key, response_queue):
        assert self.socket is not None
        assert cmd_key == 'AResponses' or cmd_key == 'UA_Responses'
        recv_wrapper = MessageWrapper('')
        while True:
            # receiving
            try:
                cmd_type = cfg.lookup_table[cmd_key]
                recv_wrapper.recv_and_parse(self.socket, cmd_type)
            except socket.timeout as e:
                # cfg.logger.debug('Timeout.')
                continue
            except SocketError as e:
                cfg.logger.debug('Error in receive: {}.'.format(e))
                continue
            except DecodeError as e:
                cfg.logger.debug('Error in decoding: {}'.format())
                continue
            except IndexError as e:
                # pass
                cfg.logger.debug('IndexError in recv_and_parse _DecodeVariant32: {}'.format(e))
                cfg.logger.debug('Stop receiving! Please re-start the backend.')
                sys.exit()
                break
        
            if recv_wrapper.get_message():
                cfg.logger.info('Received: {}'.format(recv_wrapper.get_data()))
                if cmd_key == 'AResponses':
                    if recv_wrapper.get_data().arrived or recv_wrapper.get_data().ready or recv_wrapper.get_data().loaded:
                        response_queue.put((cmd_key, recv_wrapper))
                else:
                    response_queue.put((cmd_key, recv_wrapper))

        return recv_wrapper
Esempio n. 2
0
    def get_world_id(self):
        assert self.socket is not None
        recv_wrapper = MessageWrapper('')
        start = datetime.datetime.now()
        while True:
            curr = datetime.datetime.now()
            duration = curr - start
            if duration.seconds > cfg.max_timeout:
                raise UserTimeoutException('timeout')
            try:
                recv_wrapper.recv_and_parse(self.socket, wapb.UA_Connect)
            except SocketError as e:
                cfg.logger.debug('Error in receive: {}.'.format(e))
                continue
            if recv_wrapper.get_message():
                break

        return recv_wrapper.get_data().worldid
Esempio n. 3
0
    def communicate(self, send_wrapper, cmd_key, seqnum_check=None):
        assert self.socket is not None
        recv_wrapper = MessageWrapper('')
        while True:
            # sending
            try:
                send_wrapper.encode_and_send(self.socket)
            except SocketError as e:
                if not seqnum_check:
                    cfg.logger.debug('Error in send: {}.'.format(e))
                else:
                    cfg.logger.debug('Error in send: {}.'.format(e))
                continue

            # receiving
            try:
                cmd_type = cfg.lookup_table[cmd_key]
                recv_wrapper.recv_and_parse(self.socket, cmd_type)
            except socket.timeout as e:
                # cfg.logger.debug('Timeout.')
                continue
            except SocketError as e:
                cfg.logger.debug('Error in receive: {}.'.format(e))
                continue
            except DecodeError as e:
                cfg.logger.debug('Error in decoding: {}'.format())
                continue
            except IndexError as e:
                # pass
                cfg.logger.debug('IndexError in recv_and_parse _DecodeVariant32: {}'.format(e))
                continue
        
            if recv_wrapper.get_message():
                if cmd_key != 'AResponses' and cmd_key != 'UA_Responses':
                    break
                else:
                    assert seqnum_check is not None
                    acks = recv_wrapper.get_data().acks
                    if acks and seqnum_check == acks[0]:
                        break

        return recv_wrapper