[nanomsg] Re: Receiving on a few sockets; receiving from different SP protocols

  • From: SGSeven Algebraf <a1rex2003@xxxxxxxxx>
  • To: nanomsg@xxxxxxxxxxxxx
  • Date: Sat, 29 Oct 2016 22:06:33 -0400

Thank you James for your email!

What I am trying to achieve is the blocking wait on multiple messages types
in the same thread.

What would be the most convenient is what Garrett stated on Wed, 11 May 2016
 :

"I hope to have a different, and superior, notification mechanism

involving callbacks that the application can register"

Indeed, that would be a huge, colossal breakthrough in terms of
the convenience and modern approach.

Thank you,

- Samuel




On Sat, Oct 29, 2016 at 9:17 PM, James Root <jamesroot@xxxxxxxxx> wrote:

Samuel,

I believe the best way to achieve what you are looking for is nn_poll (
http://nanomsg.org/v1.0.0/nn_poll.3.html). You store your sockets in a
way that you can look up what type they are when nn_poll tells you they are
ready.

I believe the reason a socket cannot have multiple types is because many
(all?) of the types are fundamentally different. For example, a reply
socket could never be paired with a sub socket (because you can never send
on the sub socket).

I hope this helps you!

- James Root

On Sat, Oct 29, 2016 at 8:44 PM, SGSeven Algebraf <a1rex2003@xxxxxxxxx>
wrote:

Being new to nanomsg I am not accustom yet how things work.

A few questions follows:

1)  The documentation says that I can call *nn_bind* and *nn_connect*
multiple times on the same socket .

s = nn_socket (AF_SP, NN_PAIR);

eid1 = nn_connect (s, "inproc://test");

eid2 = nn_connect (s, "tcp://127.0.0.1:5560");

Is there a way to know which endpoint sent a message (eid1 or eid2) when
I receive it by:

nn_recv (s, &buf, NN_MSG, 0);

?


2) I guess that I cannot mix different SP protocols on the same socket
and have to setup different threats for every socket type.


It would be potentially beneficial if  *nn_receive* could get a message

a) from multiple nanomsg sockets (potentially configured with different
protocols) :

nn_recv_from_sockets (*socketArray,* &buf, NN_MSG, 0);

or

b) from different protocols

I guess what I need for case  b) is:

s = nn_socket (AF_SP, *NN_ALL*);

// or

s = nn_socket (AF_SP, *NN_SUB | NN_PAIR*);

or alternatively forcing *nn_receive* to receive from different SP
senders

nn_recv (s, &buf, NN_MSG, 0, *NN_ALL)*;

Another way to be able to receive from different SP could be a

nn_recv (s, &buf, NN_MSG, 0, *NN_SUB | NN_PAIR*);


(*nn_sen*d could indicate used protocol by having an extra parameter)


Is there any way or potential benefits to provide the mentioned above
functionalities or am I misguided?


Thank you,

- Samuel



Other related posts: