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()
import time from difflib import Differ from rdt import RDTSocket if __name__ == '__main__': client = RDTSocket() # client = socket(AF_INET, SOCK_STREAM) # check what python socket does client.connect(('127.0.0.1', 9999)) echo = b'' count = 1 slice_size = 2048 blocking_send = False with open('alice.txt', 'r') as f: data = f.read() encoded = data.encode() assert len(data) == len(encoded) ''' 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)
from rdt import RDTSocket from socket import socket, AF_INET, SOCK_STREAM, SOCK_DGRAM import time from difflib import Differ from Segment import segment if __name__ == '__main__': client = RDTSocket() # client = socket(AF_INET, SOCK_DGRAM) # check what python socket does client.connect(('127.0.0.1', 10086)) echo = b'' count = 5 slice_size = 2048 blocking_send = False with open('alice.txt', 'r') as f: data = f.read() encoded = data.encode() assert len(data) == len(encoded) ''' 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)
from rdt import RDTSocket from socket import socket, AF_INET, SOCK_STREAM import time from difflib import Differ if __name__ == '__main__': client = RDTSocket(debug=False) # client = socket(AF_INET, SOCK_STREAM) # check what python socket does client.connect(('127.0.0.1', 9000)) echo = b'' count = 2 slice_size = 2048 blocking_send = False with open('data/alice30.txt', 'r') as f: data = f.read() encoded = data.encode() assert len(data) == len(encoded) ''' 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)
from rdt import RDTSocket import time from difflib import Differ from Cons import RATE, FILE, CNT client = RDTSocket(rate=RATE) client.connect(('127.0.0.1', 2777)) data_count = 0 echo = b'' count = CNT with open(FILE, '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
from rdt import RDTSocket if __name__ == '__main__': server_address = ('127.0.0.1', 33333) client = RDTSocket(rate=None) client.connect(server_address)
from rdt import RDTSocket from threading import * import time client_addr = ("127.0.0.1", 9091) client = RDTSocket() if __name__ == '__main__': client.bind(client_addr) client.connect(("127.0.0.1", 9090)) # while True: # data = input(">") # client.send(data.encode()) # # if data == 'exit': # break while True: data = client.recv(1024) print("-----------------------") print("Client Receive: ", data) print("-----------------------") if data == b'exit': break # start = time.time() # data = open("src/补充说明.pdf", 'rb').read() # client.send(data) # print(time.time() - start)