[nanomsg] bus pattern?

  • From: André Jonsson <nanomsg@xxxxxx>
  • To: nanomsg@xxxxxxxxxxxxx
  • Date: Mon, 23 Sep 2013 09:54:53 +0200

Hi all,

Now that I've successfully built nanomsg on HP-UX (woah!), I'm into a bit of experimenting.

First off I'd like make use of the BUS pattern in one part of my design, but either something is not working or something is not working the way I understand it. :)

As I understand it, a bus topology is created with a "bus" node (using bind) and "client" nodes (using connect). All sockets of NN_BUS type.

Then, all messages sent by any node in this topology is received by all other nodes. In my mind, for a useful bus topology, a minimum of three nodes is required (one bus and two clients).

Am I already off track? Thing is, I can't get it to work.

Test code:

        int s0 = nn_socket(AF_SP_RAW, NN_BUS);
        nn_bind(s0, "inproc://A");

        int s1 = nn_socket(AF_SP_RAW, NN_BUS);
        nn_connect(s1, "inproc://A");

        int s2 = nn_socket(AF_SP_RAW, NN_BUS);
        nn_connect(s2, "inproc://A");

        char buf[64];
        nn_send(s1, "B", 1, 0);
here:   nn_recv(s2, buf, 64, 0);

        nn_send(s2, "A", 1, 0);
        nn_recv(s1, buf, 64, 0);

It blocks at "here", no message is received.

But if I send a message from s0 (the "bus" node), the message is received on both the other nodes. Another thing, when sending messages between client nodes (which I assume is the point of this pattern), what happens with the bus node. Will messages arrive there too, and must be received in a timely manner? Or else?

(this was, however, tested on linux so my HP-UX build is not involved)

/André

PS. Should it be raw sockets or not?  Makes no difference in this case.

Other related posts: