Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Traceback (most recent call last):
- File "C:UsersAngelDesktopcliente.py", line 20, in <module>
- cliente.send(bytes(byte))
- ConnectionResetError: [WinError 10054] Se ha forzado la interrupción de una conexión existente por el host remoto
- import socket
- CONEXION = ("Pc-1",900)
- ARCHIVO = "a.pdf"
- cliente = socket.socket()
- cliente.connect(CONEXION)
- with open(ARCHIVO,"rb") as archivo:
- bufer = archivo.read()
- while True:
- print("Enviando bufer")
- cliente.send(str(len(bufer)).encode("ascii"))
- recibido = cliente.recv(2)
- if recibido.decode("ascii") == "ok":
- for byte in bufer:
- cliente.send(bytes(byte))
- break
- import socket
- CONEXION = (socket.gethostname(),900)
- servidor = socket.socket()
- servidor.bind(CONEXION)
- servidor.listen(1)
- print("Escuchando {}".format(CONEXION))
- sck,addr = servidor.accept()
- print("Conectado a: {}".format(addr))
- while True:
- recibido = sck.recv(1024).strip()
- if recibido:
- print("Recibido",recibido)
- if recibido.decode("ascii").isdigit():
- texto = "ok"
- sck.send(texto.encode("ascii"))
- bufer = 0
- with open("archivo.pdf","wb") as archivo:
- while(bufer<=int(recibido)):
- data = sck.recv(1)
- if not len(data):
- break
- archivo.write(data)
- bufer += 1
- if bufer == int(recibido):
- print("Archivo recibido")
- else:
- print(bufer)
- print("Error de transferencia")
- archivo.close()
- break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement