[nanomsg] missing step in pubsub example

  • From: "Jason E. Aten" <j.e.aten@xxxxxxxxx>
  • To: nanomsg <nanomsg@xxxxxxxxxxxxx>
  • Date: Sun, 14 Dec 2014 17:23:12 -0800

There is a step missing in the pub-sub example on the man page.
http://nanomsg.org/v0.5/nn_pubsub.7.html

How does the sub know to talk to the pub? There's never any connection made
between them, so the nn_recv just hangs forever.

Don't we need a bind and connect with an address in there somewhere?

Here is the example code from the man page.

int pub = nn_socket (AF_SP, NN_PUB);
int sub = nn_socket (AF_SP, NN_SUB);
int nbytes;
void *buf = NULL;

nn_setsockopt (sub, NN_SUB, NN_SUB_SUBSCRIBE, "foo", 3);
nn_setsockopt (sub, NN_SUB, NN_SUB_SUBSCRIBE, "bar", 3);

nbytes = nn_send (pub, "foo|Hello!", 10);
assert(nbytes == 10);
nbytes = nn_recv (sub, &buf, NN_MSG, 0); // hang here

Other related posts: