For connecting to the server, you need a DEALER
socket on the client side, and a ROUTER
socket on the server. Because you need a publish subscribe pattern you will need a SUB
socket on the client side, and a PUB
socket on the server side.
Client Server
+-------+ +--------+
| Dealer| <--> | Router |
| Sub | <-- | Pub |
+-------+ +--------+
So you bind the Router and the Pub sockets, and connect the Dealer, and the Sub sockets. Than when you want to:
Publish Messages (no reply expected): Create an envelope ( pub, channel, message ) and send it through the Dealer, on the Router side the router will receive the following envelope ( dealer, pub, channel, message ), so you can publish the message on channel through PUB socket.
Receive Messages (no reply expected): It's done with the SUB
sockets on the client side, and since every publication goes through the ROUTER you can easily implement a subscription mechanism, or just add a SUB
socket on the server side, and connect (inproc) to the PUB
socket (maybe this is a cleaner solution).
Request / Receive Messages (reply expected): It can be done with the Dealer - Router. you just create a different envelope ( req, message ), so your Router ( receive: dealer, req, message ) will know that it should be processed, and can send a reply to the dealer. If your server needs to send requests to the clients, you just need to keep track of the connected clients, and send an envelope (dealer, req, msg), so your dealer can reply with example a ( rep, message ) envelope.
Streaming: as you stated it can be done with the publish pattern
This is how I would do it, if you need heart beating, it gets a bit complicated, but not much.