[nanomsg] Re: publish/subscribe keys

  • From: Dirkjan Ochtman <dirkjan@xxxxxxxxxx>
  • To: nanomsg <nanomsg@xxxxxxxxxxxxx>
  • Date: Wed, 13 Aug 2014 23:08:03 +0100

On Wed, Aug 13, 2014 at 9:47 PM, John Carneiro <johncarneiro@xxxxxxxxxxx> wrote:
> It seems like this line from the example:
> nn_setsockopt (sock, NN_SUB, NN_SUB_SUBSCRIBE, "", 0)
>
> could easily be instead something like this to subscribe to a subscription
> type of "sub1":
> const char* subType = "sub1";
> nn_setsockopt (sock, NN_SUB, NN_SUB_SUBSCRIBE, subType, strlen(subType) + 1)

Yes, that's about right.

> and I would assume you could read this string on the publishing server like
> this
> char subType[100];
> getsockopt(sock, NN_SOL_SOCKET, NN_PROTOCOL, &subType, sizeof(subType));

But that is not. For now, subscriptions on the NN_SUB side of the
protocol (there may be more than one, theoretically as many as you
like) are matched against the actual message sent by the NN_PUB side.
So, if you're subscribing to "sub1\0", a message containing "sub1\0a"
from the publisher will be received, whereas a message containing
"sub2" will not.

Hopefully that's enough information to get your example working, do
ask more questions if that turns out not to be the case.

Cheers,

Dirkjan

Other related posts: