Exemplo n.º 1
0
void sendtoErr_setup(double error_rate)
{
    sendtoErr_init(error_rate, DROP_ON, FLIP_ON, DEBUG_ON, RSEED_OFF);
}
Exemplo n.º 2
0
int main (int argc, char *argv[])
{
    int32_t select_count = 0;
    int32_t buf_size = 0;
    int32_t window_size = 0;
    int32_t data_file = 0;
    int32_t packet_len = 0;
    int32_t seq_num = START_SEQ_NUM;
    uint8_t packet[MAX_LEN];
    
    STATE state = FILENAME;

    check_args(argc, argv, &buf_size, &window_size);

    sendtoErr_init(atof(argv[4]), DROP_ON, FLIP_ON, DEBUG_ON, RSEED_ON);

    //check if local file exists
    if ((data_file = open(argv[1], O_RDONLY)) < 0)
    {
        printf("File %s does not exist\n", argv[1]);
        state = DONE;
    }

    while (state != DONE)
    {
        switch (state)
        {
            case FILENAME:
                /* Everytime we try to start/restart a connection get a new socket */
                if (udp_client_setup(argv[6], atoi(argv[7]), &server) < 0)
                    exit(-1);

                state = filename(argv[2], buf_size);

                /*if no response from server then repeat sending filename (close socket) so you can open another */
                if (state == FILENAME)
                    close(server.sk_num);

                select_count++;
                if (select_count > 9) 
                {
                    printf("Server unreachable, client terminating\n");
                    state = DONE;
                }
                break;
            case FILE_OK:
                select_count = 0;
/*
                if ((output_file = open(argv[2], O_CREAT | O_TRUNC | O_WRONLY, 0600)) < 0)
                {
                    perror("File open");
                    state = DONE;
                }
                else
                    state = RECV_DATA;
*/
            case SEND_DATA:
                state = send_data(packet, &packet_len, data_file, buf_size, &seq_num);
                break;
            case DONE:
                break;
            case WAIT_ON_ACK:
                state = wait_on_ack();
                break;
            case TIMEOUT_ON_ACK:
                state = timeout_on_ack(packet, packet_len);
                break;
            default:
                printf("ERROR - in default state\n");
                state = DONE;
                break;
        }
    }
    return 0;
}