[zeromq-dev] Simple PUB / SUB test does not work

Aurélien .... kinju59 at gmail.com
Thu Sep 22 18:10:36 CEST 2016


Hi,

I'm trying to make a simple PUB / SUB test.

First, I created the publisher, then the subscriber with a message to
subscribe.

Second, I send some messages from the publisher and I try to retreive them
from the subscriber.

The code compiles but the subscriber does not receive any data.

My config is :
- Windows 7 / Visual Studio 2015
- Compile in /MTd (debug)
- ZMQ Version : 4.1.4

Here is the code :

#include "zhelpers.hpp"

void TestPubSub()
{
zmq::context_t context;
zmq::socket_t publisher(context, ZMQ_PUB);
zmq_bind(publisher, "tcp://*:5563");

zmq::socket_t subscriber(context, ZMQ_SUB);
subscriber.connect("tcp://localhost:5563");
subscriber.setsockopt(ZMQ_SUBSCRIBE, "A");

while (1) {
//  Write two messages, each with an envelope and content
s_sendmore(publisher, "A");
s_send(publisher, "We don't want to see this");
s_sendmore(publisher, "B");
s_send(publisher, "We would like to see this");

//  Read envelope with address
std::string addr = s_recv(subscriber); // block here, waiting for messages
which does not come
//  Read message contents
std::string contents = s_recv(subscriber);
}
}

int main(int argc, char** argv)
{
TestPubSub();
return 0;
}

Can you tel me where I'm wrong ?

Thank you very much,

Kin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20160922/e7db394b/attachment.htm>


More information about the zeromq-dev mailing list