-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexp3.c
64 lines (55 loc) · 1.69 KB
/
exp3.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Hello World client
// #include <stdio.h>
// #include <unistd.h>
#include "zmq.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <assert.h>
#define BUFLEN 8192
int main (void)
{
char buffer[BUFLEN];
char string[BUFLEN];
int size1;
int size2;
int64_t more = 0;
size_t more_size = sizeof(more);
printf ("Connecting to server...\n");
void *context = zmq_ctx_new ();
void *subscriber = zmq_socket(context, ZMQ_SUB);
// int rc = zmq_connect (subscriber, "tcp://138.201.156.239:5566");
// int rc = zmq_connect (subscriber, "tcp://localhost:5567");
int rc = zmq_connect (subscriber, "tcp://radio.sm7iun.se:5567");
// (void)zmq_setsockopt(subscriber, ZMQ_SUBSCRIBE, "PROD_SPOT", 9);
assert(rc == 0);
rc = zmq_setsockopt(subscriber, ZMQ_SUBSCRIBE, "SKEW_TEST", 9);
assert(rc == 0);
while (true)
{
size1 = zmq_recv (subscriber, buffer, BUFLEN, 0);
assert(size1 != -1);
// buffer[size1] = 0;
// printf("%s\n", buffer);
// memcpy(string, buffer, size1);
zmq_getsockopt(subscriber, ZMQ_RCVMORE, &more, &more_size);
if (more != 0)
{
size2 = zmq_recv(subscriber, buffer, BUFLEN, 0);
memcpy(string, buffer, size2);
}
string[size2] = 0;
// if (strncmp(buffer, "PROD_SPOT_", 10) == 0)
// {
// size = zmq_recv (subscriber, buffer, BUFLEN, 0);
// memcpy(string, buffer, size);
// string[size] = 0;
// printf("Msg: %s\n", string);
// }
printf("%s\n", string);
}
zmq_close (subscriber);
zmq_ctx_destroy (context);
return 0;
}