sender.c 1.39 KB
Newer Older
1
2
#include <stdio.h>
#include <string.h>
3
#include <stdint.h>
4
#include <unistd.h>
Andreas Schmidt's avatar
Andreas Schmidt committed
5
#include <src/util/dbg.h>
6
7
#include "prrt/socket.h"

Andreas Schmidt's avatar
Andreas Schmidt committed
8
int main(int argc, char *const argv) {
9
    int i;
Andreas Schmidt's avatar
Andreas Schmidt committed
10
    if (argc != 1) {
11
12
13
        printf("Too few arguments.\n");
    }

14
    uint16_t local_port = 6000;
15
    PrrtSocket* sock = calloc(1, sizeof(PrrtSocket));
Andreas Schmidt's avatar
Andreas Schmidt committed
16
    debug("PRRT - SENDER\n");
17

18
    int res = PrrtSocket_create(sock, local_port, TRUE);
19
    check(res == EXIT_SUCCESS, "Socket creation failed.");
20

21
22
23
    //char *remote_host = "127.0.0.1";
    //uint16_t remote_port = 5000;
    //PrrtSocket_connect(sock, remote_host, remote_port);
24

25
    char *remote_host2 = "127.0.0.1";
26
    uint16_t remote_port2 = 5004;
27
    PrrtSocket_connect(sock, remote_host2, remote_port2);
28

Andreas Schmidt's avatar
Andreas Schmidt committed
29
    debug("SENDING\n");
30

Andreas Schmidt's avatar
Andreas Schmidt committed
31
32
    FILE *fp;
    char *line = NULL;
33
34
    size_t len = 0;

35
36
    int j = 0;
    int rounds = 1;
37

38
39
40
41
42
43
44
45
46
47
48
49
50
    while(j < rounds) {
        fp = fopen("/opt/in.txt", "r");
        if (fp == NULL)
            exit(EXIT_FAILURE);

        while ((getline(&line, &len, fp)) != -1) {
            char buf[MAX_PAYLOAD_LENGTH];
            sprintf(buf, "%s", line);
            PrrtSocket_send(sock, buf, strlen(buf));
        }

        fclose(fp);
        j++;
51
    }
52
53
54
55

    if (line)
        free(line);

Andreas Schmidt's avatar
Andreas Schmidt committed
56
    usleep(1000 * 1000);
57

58
59
60
    PrrtSocket_close(sock);

    free(sock);
Andreas Schmidt's avatar
Andreas Schmidt committed
61
    debug("COMPLETELY CLOSED\n");
62
    return 0;
63
64
65

    error:
        return EXIT_FAILURE;
66
}