[nanomsg] implementing ROUTER in 0mq

  • From: Lyle Thompson <lthompson@xxxxxxxxxxx>
  • To: "nanomsg@xxxxxxxxxxxxx" <nanomsg@xxxxxxxxxxxxx>
  • Date: Tue, 13 Jan 2015 18:51:46 +0000

I am looking to reimplement a message broker that I wrote in 0mq with nanomsg. 
I was using ROUTER extensively in that implementation, which of course nanomsg 
doesn't have. So I'm just looking for some implementation advice. So it all 
starts with the receiving socket, which needs to accept connections from 
multiple sources, associate the connection "name" with that socket and prepend 
it to the message as the first "frame", and then pass the message on up. Later, 
when sending a message, I will pop the first "frame", look up the associated 
socket, and send it down.

So the first problem I'm seeing is just having a socket that serves multiple 
clients, and can identify them uniquely. So without the equivalent of a select 
or accept call, what is the best way to build a server? I'm thinking of build a 
pool of nn_pair sockets, bind them one at a time. But I see lots of potential 
problems here (Can multiple sockets bind to the same port? does a bound socket 
stop listening on the port? Etc.). But I don't see any functionality to 
automatically create an ephemeral socket on an incoming connection.

My goal is to have a single port open on the broker (maybe two including 
pub/sub).

Any suggestions would be most helpful.

Thanks!
Lyle

Other related posts: