Exemple #1
0
    os.makedirs(os.path.dirname(filename), exist_ok=True)
    numPaquetes = 0
    bytesReceived = 0
    with open(filename, 'wb+') as formatter:
        data, address = socketCliente.recvfrom(SIZE)
        while data != bytes(''.encode()):
            formatter.write(data)
            data, address = socketCliente.recvfrom(SIZE)
            numPaquetes = numPaquetes + 1
            bytesReceived = bytesReceived + len(data)

            if data == b'Fin':
                bytesReceived = bytesReceived + len(data)
                break

        buf = formatter.read()
        print('Generando el Hash del Cliente para el archivo recibido ')
        hasher.update(buf)
        hashCliente = hasher.hexdigest()

        nomArchivoR, address = socketCliente.recvfrom(SIZE)
        log.info('%s#%s', 'NOMBRE_ARCHIVO', nomArchivoR.decode('utf-8'))

        tamArchivoR, address = socketCliente.recvfrom(SIZE)
        log.info('%s#%s', 'TAMANO_ARCHIVO', tamArchivoR.decode('utf-8'))

        idClienteR, address = socketCliente.recvfrom(SIZE)
        idCli = idClienteR.decode('utf-8')
        log.info('%s#%s', 'ID_CLIENTE', idClienteR.decode('utf-8'))

        hashServidor, address = socketCliente.recvfrom(SIZE)
        while data != bytes(''.encode()):
            # print(data)
            f.write(data)
            data, address = sock.recvfrom(SIZE)
            # Send data
            #print(i,data)
            i = i + 1
            #print('received {} bytes from {}'.format(len(data), address))
            bytesReceived = bytesReceived + len(data)

            if data == b'Fin':
                bytesReceived = bytesReceived + len(data)
                print('Over')
                break

        buf = f.read()
        hasher.update(buf)
        hash_cliente = hasher.hexdigest()
        sleep(2)
        print('hash_ cliente: ', hasher.hexdigest())
        stop = False
        while not stop:
            print('arroba')
            cosa, address = sock.recvfrom(8)
            cosa = cosa.decode('utf-8')
            if str('@') in cosa:
                stop = False
            else:
                stop = True

        rcv_file_name, address = sock.recvfrom(32)