コード例 #1
0
ファイル: go_back_n_sender.py プロジェクト: rahul8436/JUCSE
    # Get command line arguments
    server_host = 'localhost'
    port = int(sys.argv[1])
    send_file = sys.argv[2]
    window_size = 8
    tempfile = 'tempfile.txt'
    # Set the maximum buffer size
    max_buff = 65535

    # Setup CRC
    crc = CRC()
    data_pkt = namedtuple('data_pkt', 'seq_num frame')
    ack_pkt = namedtuple('ack_pkt', 'seq_num ack')

    # Encode the frames
    frames = crc.encode(open(send_file, 'r').read())

    # Setup global vars
    total_frames = len(frames)
    ack_recv_till = 0
    seq_no_to_send = 0
    status = {
        'transfer_complete': False,
        'window_low': 0,
        'window_high': window_size - 1,
    }
    pickle.dump(status, open(tempfile, 'wb'))
    # COMMS
    client_socket = socket(AF_INET, SOCK_DGRAM)

    # Thread to handle ACKS
コード例 #2
0
ファイル: crc_pipe.py プロジェクト: rahul8436/JUCSE
    sys.exit(0)
else:
    # This is the child process (sender)
    encoder = CRC()
    os.close(r_chan)
    os.close(w_ack)
    w_chan = os.fdopen(w_chan, 'w')
    r_ack = os.fdopen(r_ack)
    print("Child writing")

    # Read file to send
    with open('input.txt', 'r') as f:
        text = f.read()

    # Send the length
    frames = encoder.encode(text=text, verbose=True)
    length = str(len(frames)) + '\n'
    print(length)
    os.write(w_chan, length)
    r_ack.readline()[:-1]
    print('lol')
    # Sending process
    i = 0
    while i < len(text):
        w_chan.write(text[i])
        print('lol2')
        ack = r_ack.read()
        print(ack)
        if ack == '1':
            i -= 1