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

using namespace std;

#include <zmq.hpp>

using namespace zmq;

const string TOPIC = "1234";

void test(string addr)
{
    context_t ctx;
    socket_t s(ctx, socket_type::sub);
    s.connect(addr);
    s.set(sockopt::subscribe, TOPIC);
    int n = 0;
    while(n < 3) 
    {
        message_t temp;
        s.recv(temp, recv_flags::none);
        string respmsg = temp.to_string();
        respmsg = respmsg.substr(TOPIC.size() + 1);
        cout << "C++ client : " << respmsg << endl;
        n++;
    }
}

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;
}
