Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. def send_data(data, port): #sends "data" to (host @ port)
  2. host = 'localhost'
  3. c = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  4. c.sendto(bytes(data, encoding),(host,port)) #send message
  5. c.close
  6.  
  7. def recv_data(buffer_limit, port):
  8. host = 'localhost'
  9. c = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  10. c.bind((host, port))
  11. received = c.recv(buffer_limit).decode(encoding) # waiting for acknowledgment
  12. c.close
  13. c = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  14. return (received)
  15.  
  16. with open(file_path, file_mode) as file:
  17. data = file.readlines() #reads the binary file to variable data
  18.  
  19. def package_data(file_length, buffer_limit, port): #takes individually received lines and packages them into a single array
  20. file = []
  21. x = file_length
  22. while x!=0:
  23. file.append(recv_data(buffer_limit, port))
  24. x-=1
  25. for line in file:
  26. sys.stdout.write(line)
  27. return (file)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement