예제 #1
0
for iteration in range(ITERATIONS):
    if iteration % 10 == 0:
        print('iteration %s' % iteration)

    action = random()

    if ((action < 0.05 and from_client)
            or (action < 0.5 and len(from_client) >= MAX_FROM_CLIENT)):
        number_to_check = randint(1, len(from_client))
        # print('recv from client (%s of %s)' %
        #      (number_to_check, len(from_client)))

        for b in from_client[:number_to_check]:
            # print('recv from client')
            actual_length = clientsocket.myreceive(2)
            expected_length = get_length_in_network_bytes(b)
            # print(expected_length)
            # print(actual_length)
            assert actual_length == expected_length
            actual_data = clientsocket.myreceive(len(b))
            # print(b)
            # print(actual_data)
            assert actual_data == b
        from_client = from_client[number_to_check:]
    elif action < 0.5:
        # print('write from client')
        b = generate_random_bytes_line()
        client.stdin.write(b + b'\n')
        client.stdin.flush()
        from_client.append(b)
예제 #2
0
파일: test_client.py 프로젝트: starsep/sik1
for iteration in range(ITERATIONS):
    if iteration % 10 == 0:
        print('iteration %s' % iteration)

    action = random()

    if ((action < 0.05 and from_client)
        or (action < 0.5 and len(from_client) >= MAX_FROM_CLIENT)):
        number_to_check = randint(1, len(from_client))
        # print('recv from client (%s of %s)' %
        #      (number_to_check, len(from_client)))

        for b in from_client[:number_to_check]:
            # print('recv from client')
            actual_length = clientsocket.myreceive(2)
            expected_length = get_length_in_network_bytes(b)
            # print(expected_length)
            # print(actual_length)
            assert actual_length == expected_length
            actual_data = clientsocket.myreceive(len(b))
            # print(b)
            # print(actual_data)
            assert actual_data == b
        from_client = from_client[number_to_check:]
    elif action < 0.5:
        # print('write from client')
        b = generate_random_bytes_line()
        client.stdin.write(b + b'\n')
        client.stdin.flush()
        from_client.append(b)
예제 #3
0
sendall() :TCP
recvfrom() :UDP
recvfrom_into() :UDP
sendto() :UDP
'''
HOST = 'localhost'
# HOST = '::1'
PORT = 9999
ADDR = (HOST, PORT)
if __name__ == "__main__":
    # s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
    # s.settimeout(5)
    # s.connect(ADDR)
    # print(s.recv(1024).decode('utf-8'))
    # for data in [b'Tony', b'Nick', b'Ulysses']:

    #     s.send(data)
    #     print(s.recv(1024).decode('utf-8'))

    # s.send(b'exit')
    # s.close()
    s = MySocket()
    s.connect(HOST, PORT)
    print(s.myreceive(32).decode('utf-8'))
    for data in [b'Tony', b'Nick', b'Ulysses']:
        print(len(data))
        s.mysend(data)
        print(s.myreceive(32).decode('utf-8'))
    s.mysend(b'exit')
    s.close()
예제 #4
0
if __name__ == "__main__":
    IP = "chals3.umdctf.io"
    PORT = 6001
    SUFFIX = '\n\n'

    addtuple = (IP, PORT)
    # create an INET, STREAMing socket
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

    client = MySocket(s)
    client.connect(IP, PORT)
    initialMessage = client.myreceive2Suffix(SUFFIX)
    print("{}\nMessage : {}".format(initialMessage, len(initialMessage)))
    response = "\n".encode()
    client.mysend(response)
    arr = client.myreceive2Suffix(SUFFIX)
    # Before passing the list along we have to clean the data,
    # becasue it is a string at this point
    print("{}\nArray : {}".format(arr, len(arr)))
    newarr = arr.lstrip("[").rstrip("]\n")
    listRes = list(newarr.split(", "))
    listInts = list(map(int, listRes))
    result = maxSubArraySum(listInts, len(listInts))

    response = "{}, {}, {}".format(*result).encode()
    print("Response is: {} ".format(response.decode()))
    client.mysend(response)

    flag = client.myreceive()
    print(flag)