/* Collection of code snippets by Arne Vajhøj */
/* (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) */
#include <stdio.h>
#include <string.h>

#include <zmq.h>

#define TOPIC "1234"

void test(const char *addr)
{   
    void *ctx;
    void *s;
    char respmsg[10000], *respmsg2;
    int n, msglen;
    ctx = zmq_ctx_new();
    s = zmq_socket(ctx, ZMQ_SUB);;
    zmq_connect(s, addr);
    zmq_setsockopt(s, ZMQ_SUBSCRIBE, TOPIC, 0);
    n = 0;
    while(n < 3)
    {
        msglen = zmq_recv(s, respmsg, sizeof(respmsg), 0);
        respmsg[msglen] = 0;
        respmsg2 = respmsg + strlen(TOPIC) + 1;
        printf("C (low) client : %s\n", respmsg2);
        n++;
    }
    zmq_close(s);
    zmq_ctx_destroy(ctx);
}

int main(void)
{
    test("tcp://localhost:10001");
    test("tcp://localhost:10002");
    test("tcp://localhost:10003");
    test("tcp://localhost:10004");
    test("tcp://localhost:10005");
    test("tcp://localhost:10006");
    return 0;
}
