Que tan grande el archivo? Cuanto es mucho tiempo? On Sun, Apr 21, 2019 at 5:50 PM PeRy <pery...@gmail.com> wrote:
> > Buenas! Estoy aprendiendo Python y estoy con el tema de los sockets, he > creado un servidor y cliente para enviar archivos. Me he dado cuenta que en > archivos grandes cuanto mas pasa el tiempo mas lenta se hace la recepción > de la información, ¿alguna sugerencia por qué pasa y como se podría evitar? > mi codigo: > > server: > > ============================================================================================= > elif b'\F' in data: # peticion de archivo para ser descargado > transmitido = data.rstrip(b'\F') > comparte_dir = os.path.join(os.getcwd(), 'compartir') > print(os.path.join(comparte_dir, transmitido.decode())) > filesize = os.path.getsize(os.path.join(comparte_dir, > transmitido.decode())) > print("TAMAÑO: {}".format(filesize)) > with open(os.path.join(comparte_dir, transmitido.decode()), 'rb') as f: > self.socket.send(struct.pack('!I', filesize)) # enviamos en los primeros > 4bytes el tamaño del archivo > numero_bytes = self.socket.sendfile(f) > # data = f.read(8192) > # numero_bytes = len(data) > # self.socket.send(data) > # while data: > # data = f.read(8192) > # self.socket.send(data) > # numero_bytes += len(data) > print(numero_bytes) > > cliente: > > =============================================================================================== > with open(archivo, 'wb') as f: > buf = socket_cliente.recv(4) # cabecera con elt > amaño del archivo > filesize = struct.unpack('!I', buf) > print("filesize : {}".format(filesize)) > filesize=filesize[0] > buf = b'' > tiempo_inicio = datetime.datetime.now() > print(tiempo_inicio.strftime('%H:%M:%S')) > while len(buf) < filesize: > to_read = filesize - len(buf) > buf += socket_cliente.recv(262144 if to_read > > 262144 else to_read) #8192 1024*8 o 4096 1024*4 > updt(filesize, len(buf)) # barra de progreso > f.write(buf) > > --------------------- > Muchas Gracias y un saludo > > _______________________________________________ > Python-es mailing list > Python-es@python.org > https://mail.python.org/mailman/listinfo/python-es > -- Arturo Muñoz Tolosa
_______________________________________________ Python-es mailing list Python-es@python.org https://mail.python.org/mailman/listinfo/python-es