def server_test(debug_model: bool): server = RDTSocket(debug=debug_model) server.bind((SERVER_ADDR, SERVER_PORT)) try: while True: conn, client_addr = server.accept() Echo(conn, client_addr).start() except KeyboardInterrupt as k: print(k)
from Cons import RATE, DEBUG from rdt import RDTSocket import time if __name__ == '__main__': server = RDTSocket(debug=DEBUG, rate=RATE) server.bind(('127.0.0.1', 9999)) while True: conn, client_addr = server.accept() start = time.perf_counter() while True: data = conn.recv(2048) if data: conn.send(data) else: break ''' make sure the following is reachable ''' conn.close() print(f'connection finished in {time.perf_counter()-start}s')
from Cons import * from rdt import RDTSocket import time from difflib import Differ client = RDTSocket(debug=DEBUG, rate=RATE) client.bind(('127.0.0.1', 9998)) client.connect(('127.0.0.1', 9999)) data_count = 0 echo = b'' count = CNT with open(FILE, 'rb') as f: data = f.read() encoded = data 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:
from rdt import RDTSocket if __name__ == '__main__': client_address = ('127.0.0.1', 44444) client = RDTSocket(rate=None) client.bind(client_address)
from rdt import RDTSocket import time from Cons import RATE if __name__ == '__main__': server = RDTSocket(rate=RATE) server.bind(('127.0.0.1', 2777)) while True: conn, client_addr = server.accept() start = time.perf_counter() while True: data = conn.recv(2048) if data: conn.send(data) else: break ''' make sure the following is reachable ''' conn.close() print(f'connection finished in {time.perf_counter()-start}s')
from rdt import RDTSocket from socket import socket, AF_INET, SOCK_DGRAM, SOCK_STREAM import time if __name__ == '__main__': server = RDTSocket() # server = socket(AF_INET, SOCK_STREAM) # check what python socket does server.bind(('127.0.0.1', 10086)) # server.listen(0) # check what python socket does while True: print("----------SERVER START TO ACCEPT-------------") conn, client_addr = server.accept() start = time.perf_counter() while True: data = conn.recv(2048) if data: # pass conn.send(data) else: break ''' make sure the following is reachable ''' conn.close() print(f'connection finished in {time.perf_counter() - start}s')
from rdt 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.bind(('127.0.0.1', 8999)) client.connect(('127.0.0.1', 9999)) echo = b'' count = 3 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 if __name__ == '__main__': server_address = ('127.0.0.1', 33333) server = RDTSocket(rate=None) server.bind(server_address) while True: conn, client = server.accept()
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)
from rdt import RDTSocket if __name__ == "__main__": try: server = RDTSocket() server.bind(("127.0.0.1", 1234)) # 这个叫 server 的 socket 只用来监听连接请求,有一个 client 想连接,server 就给这个 clinet 分配一个专属的 conn,在 conn 上收发数据 while True: conn, addr = server.accept() while True: data = conn.recv(1024000) if data: print("received payload: " + data.decode()) if data == b"exit": break elif data == b"quit": print("Server Closed") exit() else: break conn.close() print("Server Connection Lost") except KeyboardInterrupt: exit()
from rdt import RDTSocket server_addr = ("127.0.0.1", 9090) server = RDTSocket() if __name__ == '__main__': server.bind(server_addr) conn, addr = server.accept() # while True: # data = conn.recv(1024) # print("-----------------------") # print("Server Receive: ", data) # print("-----------------------") # # if data == b'exit': # break while True: data = input(">") conn.send(data.encode()) if data == 'exit': break # with open("dst/补充说明1.pdf", mode='wb') as file: # data = conn.recv(1024000000) # print("-----------------------") # print("Server Receive!") # print("-----------------------")
from rdt import RDTSocket from socket import socket, AF_INET, SOCK_DGRAM, SOCK_STREAM import time if __name__ == '__main__': server = RDTSocket() # server = socket(AF_INET, SOCK_STREAM) # check what python socket does server.bind(('127.0.0.1', 9000)) # check what python socket does # server.listen(0) while True: conn, client_addr = server.accept() print(conn) start = time.perf_counter() while True: data = conn.recv(2048) if data: conn.send(data) else: break ''' make sure the following is reachable ''' conn.close() print(f'connection finished in {time.perf_counter() - start}s')