Beispiel #1
0
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)
Beispiel #2
0
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')
Beispiel #3
0
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()
Beispiel #4
0
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()