SHARE
TWEET

Untitled

a guest Jun 20th, 2019 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import socket
  2.  
  3. CONEXION = (socket.gethostname(),900)
  4. servidor = socket.socket()
  5.  
  6. servidor.bind(CONEXION)
  7. servidor.listen(1)
  8.  
  9. pdf = "pdf"
  10. mp3 = "mp3"
  11.  
  12. respuesta = int( input("Que archivo desea reibir?n1.-Pdfn2.-Mp3n"))
  13.  
  14. while True:
  15.     sc,addr = servidor.accept()
  16.     if respuesta == 1:
  17.         sc.send(pdf.encode("ascii"))
  18.         i = 1
  19.         f = open("file1.pdf","wb")
  20.         l = i+1
  21.         while True:
  22.             l = sc.recv(1024)
  23.             while l:
  24.                 f.write(l)
  25.                 l = sc.recv(1024)
  26.             if not len(l):
  27.                 f.close()
  28.                 break
  29.         r = sc.recv(2)
  30.         print(r)
  31.         if r.decode("ascii")!= None:
  32.             res = "ok"
  33.             sc.send(res.encode("ascii"))
  34.         else:
  35.             sc.close()
  36. servidor.close()
  37.      
  38. import socket
  39.  
  40. cliente = socket.socket()
  41. cliente.connect(("Pc-1",900))
  42.  
  43. rec1 = cliente.recv(3)
  44. if rec1.decode("ascii") == "pdf":
  45.     f = open("a.pdf","rb")
  46.     l = f.read(1024)
  47.  
  48.     while l:
  49.         cliente.send(l)
  50.         l = f.read(1024)
  51. texto = "ok"
  52. cliente.send(texto.encode("ascii"))
  53. res = cliente.recv(2)
  54. if res.decode("ascii") == "ok":
  55.     cliente.close()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top