Example #1
0
    parser.add_argument('server', help='Server.')
    parser.add_argument('port', help='Port.', type=int)
    args = parser.parse_args()

    msg_L = [
        'The use of COBOL cripples the mind; its teaching should, therefore, be regarded as a criminal offense. -- Edsgar Dijkstra',
        'C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg. -- Bjarne Stroustrup',
        'A mathematician is a device for turning coffee into theorems. -- Paul Erdos',
        'Grove giveth and Gates taketh away. -- Bob Metcalfe (inventor of Ethernet) on the trend of hardware speedups not being able to keep up with software demands',
        'Wise men make proverbs, but fools repeat them. -- Samuel Palmer (1805-80)'
    ]

    timeout = 2  #send the next message if not response
    time_of_last_data = time.time() + 100000000

    rdt = rdt_2_1.RDT('client', args.server, args.port)
    for msg_S in msg_L:
        print('Converting: ' + msg_S)
        rdt.rdt_2_1_send(msg_S)

        # try to receive message before timeout
        msg_S = None
        while msg_S == None:
            msg_S = rdt.rdt_2_1_receive()
            if msg_S is None:
                if time_of_last_data + timeout < time.time():
                    break
                else:
                    continue
        #time_of_last_data = time.time()
Example #2
0

def NACK():
    return "NACK"


if __name__ == '__main__':
    parser = argparse.ArgumentParser(
        description='Pig Latin conversion server.')
    parser.add_argument('port', help='Port.', type=int)
    args = parser.parse_args()

    timeout = 5  #close connection if no new data within 5 seconds
    time_of_last_data = time.time()

    rdt = rdt_2_1.RDT('server', None, args.port)

    corrupt = False
    while (True):
        #try to receiver message before timeout
        msg_S, corrupt = rdt.rdt_2_1_receive()
        if corrupt:
            print('\nReceived corrupt package. Sending NACK\n')
            #send NACK package
            rdt.rdt_2_1_send(NACK())
            #print('Got a corrupt package, sending NACK')
            #reset time_of_last_data to avoid timeout
            time_of_last_data = time.time()
            #skip over rest of loop so it doesn't try to
            #piglatinize it
            msg_S = ''
Example #3
0
    parser.add_argument('server', help='Server.')
    parser.add_argument('port', help='Port.', type=int)
    args = parser.parse_args()

    msg_L = [
        'The use of COBOL cripples the mind; its teaching should, therefore, be regarded as a criminal offense. -- Edsgar Dijkstra',
        'C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg. -- Bjarne Stroustrup',
        'A mathematician is a device for turning coffee into theorems. -- Paul Erdos',
        'Grove giveth and Gates taketh away. -- Bob Metcalfe on the trend of hardware speedups not being able to keep up with software demands',
        'Wise men make proverbs, but fools repeat them. -- Samuel Palmer'
    ]

    timeout = 2  # send the next message if no response
    time_of_last_data = time.time()

    rdt = RDT.RDT('client', args.server, args.port)
    for msg_S in msg_L:
        print('Converting: ' + msg_S)
        rdt.rdt_2_1_send(0, msg_S)

        # try to receive message before timeout
        msg_S = None
        while msg_S == None:
            msg_S = rdt.rdt_2_1_receive()
            if msg_S is None:
                if time_of_last_data + timeout < time.time():
                    break
                else:
                    continue
        time_of_last_data = time.time()
Example #4
0
    message = message.strip(".")
    for word in message.split(' '):
        essagemay += " " + makePigLatin(word)
    return essagemay.strip() + "."


if __name__ == '__main__':
    parser = argparse.ArgumentParser(
        description='Pig Latin conversion server.')
    parser.add_argument('port', help='Port.', type=int)
    args = parser.parse_args()

    timeout = 5  # close connection if no new data within 5 seconds
    time_of_last_data = time.time()

    rdt = RDT.RDT('server', None, args.port)
    while (True):
        # try to receiver message before timeout
        msg_S = rdt.rdt_2_1_receive()
        if msg_S is None:
            if time_of_last_data + timeout < time.time():
                break
            else:
                continue
        time_of_last_data = time.time()

        # convert and reply
        rep_msg_S = piglatinize(msg_S)
        print('Converted %s \nto \n%s\n' % (msg_S, rep_msg_S))
        rdt.rdt_2_1_send(0, rep_msg_S)
Example #5
0
    message = message.strip(".")
    for word in message.split(' '):
        essagemay += " " + makePigLatin(word)
    return essagemay.strip() + "."


if __name__ == '__main__':
    parser = argparse.ArgumentParser(
        description='Pig Latin conversion server.')
    parser.add_argument('port', help='Port.', type=int)
    args = parser.parse_args()

    timeout = 5  #close connection if no new data within 5 seconds
    time_of_last_data = time.time()

    rdt = rdt.RDT('server', None, args.port)
    while (True):
        #try to receiver message before timeout
        msg_S = rdt.rdt_2_1_receive()
        if msg_S is None:
            if time_of_last_data + timeout < time.time():
                break
            else:
                continue
        time_of_last_data = time.time()

        #convert and reply
        rep_msg_S = piglatinize(msg_S)
        print('Converted %s \nto \n%s\n' % (msg_S, rep_msg_S))
        rdt.rdt_2_1_send(rep_msg_S)