Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def send_data(data, port): #sends "data" to (host @ port)
- host = 'localhost'
- c = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
- c.sendto(bytes(data, encoding),(host,port)) #send message
- c.close
- def recv_data(buffer_limit, port):
- host = 'localhost'
- c = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
- c.bind((host, port))
- received = c.recv(buffer_limit).decode(encoding) # waiting for acknowledgment
- c.close
- c = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
- return (received)
- with open(file_path, file_mode) as file:
- data = file.readlines() #reads the binary file to variable data
- def package_data(file_length, buffer_limit, port): #takes individually received lines and packages them into a single array
- file = []
- x = file_length
- while x!=0:
- file.append(recv_data(buffer_limit, port))
- x-=1
- for line in file:
- sys.stdout.write(line)
- return (file)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement