from rdt2_0 import RDTSocket from threading import * import time client_addr = ("127.0.0.1", 9092) client = RDTSocket() if __name__ == '__main__': client.bind(client_addr) client.connect(("127.0.0.1", 9090)) start = time.time() with open("../src/补充说明.pdf", 'rb') as file: data = file.read() client.send(data) with open("../dst/补充说明2.pdf", mode='wb') as file: data = client.recv(1024000000) print("-----------------------") print("Server Receive!", time.time() - start) print("-----------------------") file.write(data) client.close() print("Program exit!") # while True: # data = input(">") # client.send(data.encode()) # # if data == 'exit':
''' check if your rdt pass either of the two mode A may be significantly slower when slice size is small ''' if blocking_send: print('transmit in mode A, send & recv in slices') slices = [ encoded[i * slice_size:i * slice_size + slice_size] for i in range(len(encoded) // slice_size + 1) ] assert sum([len(slice) for slice in slices]) == len(encoded) start = time.perf_counter() for i in range(count): # send 'alice.txt' for count times for slice in slices: client.send(slice) reply = client.recv(slice_size) echo += reply else: print('transmit in mode B') start = time.perf_counter() for i in range(count): client.send(encoded) while len(echo) < len(encoded) * (i + 1): reply = client.recv(slice_size) echo += reply client.close() ''' make sure the following is reachable '''
from rdt2_0 import RDTSocket from threading import * import time client_addr = ("127.0.0.1", 9092) client = RDTSocket() if __name__ == '__main__': client.bind(client_addr) client.connect(("127.0.0.1", 9090)) while True: msg = input(">") client.send(msg.encode()) if msg == '0': break client.close() print("Program exit!")
client = RDTSocket() client.connect(('127.0.0.1', 9999)) data_count = 0 echo = b'' count = 3 with open('alice.txt', 'r') as f: data = f.read() encoded = data.encode() assert len(data) == len(encoded) start = time.perf_counter() for i in range(count): # send 'alice.txt' for count times data_count += len(data) client.send(encoded) ''' blocking send works but takes more time ''' while True: reply = client.recv(2048) echo += reply print(reply) if len(echo) == len(encoded) * count: break client.close() ''' make sure the following is reachable '''