UDPFile_receiver.py
def parse_file_data(self, data):
        ''' Parse received file data from sender application
            to body and header, check corruption as well. '''

        header, skip = self.parse_data(data, int_format=False)
        body = data[HEADER_SIZE:]
        ret_dict = {}
        ret_dict["valid"] = False
        ret_dict["body"] = []
        ret_dict["body_len"] = 0
        ret_dict["parsed_transfer_window_idx"] = 0

        # NET DERPER CHANGES FIRST NUM TO CHAR
        if not str(chr(header[0])).isnumeric():
            ret_dict["return"] = PARSE_RETURNS["wrong_message_type"]
            return ret_dict

        message_type = int(str(chr(header[0])))

        if message_type != (MESSAGE_TYPES['file_data_sent']): 
            print(f'ERROR in parse_file_data(): Message type {message_type} doesn\'t match {MESSAGE_TYPES["file_data_sent"]}')
            ret_dict["return"] = PARSE_RETURNS["wrong_message_type"]
            return ret_dict
        
        print(f"len of parse file data: {len(data)}")
        # Check CRC
        print(f"CCCHEECK : {np.concatenate((header, skip), axis=None)}")
        print(f"len bytes(data): {len(bytes(data))}")
        if not check_crc_received_message(np.concatenate((header, skip), axis=None)):
            ret_dict["return"] = PARSE_RETURNS["wrong_crc"]
            return ret_dict

        ## GET INFO FROM HEADER
        # Get message window idx
        transfer_window_idx = '0'
        header_transfer_window_idx = header[FILE_DATA_HEADER_TRANSFER_WINDOW_START_IDX:FILE_DATA_HEADER_TRANSFER_WINDOW_START_IDX+FILE_DATA_HEADER_TRANSFER_WINDOW_MAX_LEN]
        pop_zeros(header_transfer_window_idx)
        for header_int_char in header_transfer_window_idx:
            # if header_int_char == 0: break
            print(f"header_int_char: {header_int_char}")
            transfer_window_idx = transfer_window_idx + str(chr(header_int_char))
        print(f"transfer_window_idx: {transfer_window_idx}")
        # Length of data in the body, information is stored in the header
        data_body_len = '0'
        header_body_len_info = header[FILE_DATA_HEADER_BODY_LEN_START_IDX:FILE_DATA_HEADER_BODY_LEN_START_IDX+FILE_DATA_HEADER_MAX_BODY_LEN]
        print(f"received header: {header}")
        print(f"header len: {len(header)}, header_body_len_info len: {len(header_body_len_info)}")
        pop_zeros(header_body_len_info)
        for header_int_char in header_body_len_info:
            # if header_int_char == 0: break
            print(f"header_int_char: {header_int_char}")
            data_body_len = data_body_len + str(chr(header_int_char))
        print(f"data_body_len: {data_body_len}")

        ret_dict["valid"] = True
        ret_dict["body"] = body
        ret_dict["body_len"] = int(data_body_len)
        ret_dict["parsed_transfer_window_idx"] = int(transfer_window_idx)
        ret_dict["return"] = PARSE_RETURNS["request_successful"]
        return ret_dict
 Parse received file data from sender application
            to body and header, check corruption as well. 
Parse received file data from sender application
to body and header, check corruption as well.
Parse received file data from sender application to body and header check corruption as well .
def parse_file_data(self, data):
        header, skip = self.parse_data(data, int_format=False)
        body = data[HEADER_SIZE:]
        ret_dict = {}
        ret_dict["valid"] = False
        ret_dict["body"] = []
        ret_dict["body_len"] = 0
        ret_dict["parsed_transfer_window_idx"] = 0
        if not str(chr(header[0])).isnumeric():
            ret_dict["return"] = PARSE_RETURNS["wrong_message_type"]
            return ret_dict
        message_type = int(str(chr(header[0])))
        if message_type != (MESSAGE_TYPES['file_data_sent']): 
            print(f'ERROR in parse_file_data(): Message type {message_type} doesn\'t match {MESSAGE_TYPES["file_data_sent"]}')
            ret_dict["return"] = PARSE_RETURNS["wrong_message_type"]
            return ret_dict
        print(f"len of parse file data: {len(data)}")
        print(f"CCCHEECK : {np.concatenate((header, skip), axis=None)}")
        print(f"len bytes(data): {len(bytes(data))}")
        if not check_crc_received_message(np.concatenate((header, skip), axis=None)):
            ret_dict["return"] = PARSE_RETURNS["wrong_crc"]
            return ret_dict
        transfer_window_idx = '0'
        header_transfer_window_idx = header[FILE_DATA_HEADER_TRANSFER_WINDOW_START_IDX:FILE_DATA_HEADER_TRANSFER_WINDOW_START_IDX+FILE_DATA_HEADER_TRANSFER_WINDOW_MAX_LEN]
        pop_zeros(header_transfer_window_idx)
        for header_int_char in header_transfer_window_idx:
            print(f"header_int_char: {header_int_char}")
            transfer_window_idx = transfer_window_idx + str(chr(header_int_char))
        print(f"transfer_window_idx: {transfer_window_idx}")
        data_body_len = '0'
        header_body_len_info = header[FILE_DATA_HEADER_BODY_LEN_START_IDX:FILE_DATA_HEADER_BODY_LEN_START_IDX+FILE_DATA_HEADER_MAX_BODY_LEN]
        print(f"received header: {header}")
        print(f"header len: {len(header)}, header_body_len_info len: {len(header_body_len_info)}")
        pop_zeros(header_body_len_info)
        for header_int_char in header_body_len_info:
            print(f"header_int_char: {header_int_char}")
            data_body_len = data_body_len + str(chr(header_int_char))
        print(f"data_body_len: {data_body_len}")
        ret_dict["valid"] = True
        ret_dict["body"] = body
        ret_dict["body_len"] = int(data_body_len)
        ret_dict["parsed_transfer_window_idx"] = int(transfer_window_idx)
        ret_dict["return"] = PARSE_RETURNS["request_successful"]
        return ret_dict
def parse_file_data ( self , data ) : header , skip = self . parse_data ( data , int_format = False ) body = data [ HEADER_SIZE : ] ret_dict = { } ret_dict [ "valid" ] = False ret_dict [ "body" ] = [ ] ret_dict [ "body_len" ] = 0 ret_dict [ "parsed_transfer_window_idx" ] = 0 if not str ( chr ( header [ 0 ] ) ) . isnumeric ( ) : ret_dict [ "return" ] = PARSE_RETURNS [ "wrong_message_type" ] return ret_dict message_type = int ( str ( chr ( header [ 0 ] ) ) ) if message_type != ( MESSAGE_TYPES [ 'file_data_sent' ] ) : print ( f'ERROR in parse_file_data(): Message type {message_type} doesn\'t match {MESSAGE_TYPES["file_data_sent"]}' ) ret_dict [ "return" ] = PARSE_RETURNS [ "wrong_message_type" ] return ret_dict print ( f"len of parse file data: {len(data)}" ) print ( f"CCCHEECK : {np.concatenate((header, skip), axis=None)}" ) print ( f"len bytes(data): {len(bytes(data))}" ) if not check_crc_received_message ( np . concatenate ( ( header , skip ) , axis = None ) ) : ret_dict [ "return" ] = PARSE_RETURNS [ "wrong_crc" ] return ret_dict transfer_window_idx = '0' header_transfer_window_idx = header [ FILE_DATA_HEADER_TRANSFER_WINDOW_START_IDX : FILE_DATA_HEADER_TRANSFER_WINDOW_START_IDX + FILE_DATA_HEADER_TRANSFER_WINDOW_MAX_LEN ] pop_zeros ( header_transfer_window_idx ) for header_int_char in header_transfer_window_idx : print ( f"header_int_char: {header_int_char}" ) transfer_window_idx = transfer_window_idx + str ( chr ( header_int_char ) ) print ( f"transfer_window_idx: {transfer_window_idx}" ) data_body_len = '0' header_body_len_info = header [ FILE_DATA_HEADER_BODY_LEN_START_IDX : FILE_DATA_HEADER_BODY_LEN_START_IDX + FILE_DATA_HEADER_MAX_BODY_LEN ] print ( f"received header: {header}" ) print ( f"header len: {len(header)}, header_body_len_info len: {len(header_body_len_info)}" ) pop_zeros ( header_body_len_info ) for header_int_char in header_body_len_info : print ( f"header_int_char: {header_int_char}" ) data_body_len = data_body_len + str ( chr ( header_int_char ) ) print ( f"data_body_len: {data_body_len}" ) ret_dict [ "valid" ] = True ret_dict [ "body" ] = body ret_dict [ "body_len" ] = int ( data_body_len ) ret_dict [ "parsed_transfer_window_idx" ] = int ( transfer_window_idx ) ret_dict [ "return" ] = PARSE_RETURNS [ "request_successful" ] return ret_dict
Parse received file data from sender application
to body and header, check corruption as well.
Parse received file data from sender application to body and header check corruption as well .
''' Parse received file data from sender application
            to body and header, check corruption as well. ''' # NET DERPER CHANGES FIRST NUM TO CHAR
 # Check CRC
 ## GET INFO FROM HEADER
 # Get message window idx
 # if header_int_char == 0: break
 # Length of data in the body, information is stored in the header
 # if header_int_char == 0: break

self
data