def client_test(file_path, debug): client = RDTSocket(debug=debug) if client.connect((SERVER_ADDR, SERVER_PORT)): data_count = 0 count = 20 f = open(file_path, 'rb') data_send = f.read() start = time.perf_counter() for i in range(count): # send data for count times data_count += len(data_send) client.send(data_send) data_send = data_send * count mid = time.perf_counter() print('---------------------------------------------') print( f'client send OK, data size: {unit_convert(len(data_send))}, send time cost: {mid - start} s' ) print('---------------------------------------------') echo = bytearray() while True: reply = client.recv(2048) echo.extend(reply) assert echo == data_send[:len(echo)], 'Inconsistent echo content' if len(echo) == len(data_send): break end = time.perf_counter() print('=============================================') print( f'client recv OK, data size: {unit_convert(len(echo))} bytes, recv time cost: {end - mid} s' ) print(f'Total time cost: {end - start}') print('=============================================') client.close() print('client main thread stop.')
from rdt import RDTSocket if __name__ == "__main__": try: client = RDTSocket() client.connect(("127.0.0.1", 1234)) while True: print("input data:") data = input() if data == "alice": data = open("alice.txt", "r").read() client.send(data.encode()) if data == "exit" or data == "quit": break client.close() print("Client Closed") except KeyboardInterrupt: exit()