예제 #1
0
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.')
예제 #2
0
    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()
        for i in range(count):  # send 'alice.txt' for count times
            for slice in slices:
                client.send(slice)
                reply = client.recv(slice_size)
                echo += reply
    else:
        print('transmit in mode B')
        start = time.perf_counter()
        for i in range(count):
            client.send(encoded)
            while len(echo) < len(encoded) * (i + 1):
                reply = client.recv(slice_size)
                echo += reply

    client.close()
    '''
    make sure the following is reachable
    '''
예제 #3
0
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:
        break
client.close()
'''
make sure the following is reachable
'''

print(f'transmitted {data_count * 2}bytes in {time.perf_counter() - start}s')
print(f'tr = {data_count * 2 / (time.perf_counter() - start) / 1000} KB/s\n')
# client.save_perf('100K_c_l_10k.json')
diff = Differ().compare((data * count).splitlines(keepends=True),
                        echo.splitlines(keepends=True))
for line in diff:
예제 #4
0
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)

    # data = open("2-1.PNG", 'rb').read()
    # client.send(data)