from rdt2_0 import RDTSocket from socket import socket, AF_INET, SOCK_STREAM import time from difflib import Differ if __name__ == '__main__': # client = RDTSocket() # client = socket(AF_INET, SOCK_STREAM) # check what python socket does client = RDTSocket(debug=True) # check what python socket does client.connect(('127.0.0.1', 9999)) echo = b'' count = 10 slice_size = 2048 blocking_send = False # with open('alice.txt', 'r') as f: 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) ]
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':
from rdt2_0 import RDTSocket from socket import socket, AF_INET, SOCK_STREAM import time from difflib import Differ if __name__=='__main__': # client = RDTSocket() # client = socket(AF_INET, SOCK_STREAM) # check what python socket does client = RDTSocket(rate=5000, debug=True) # check what python socket does client.connect(('127.0.0.1', 33333)) 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) start = time.perf_counter()