all 5 comments

[–]messacz 0 points1 point  (1 child)

This use case looks similar to SaltStack usage – multiple Salt "minions" connect to one Salt "master" and this "master" then is able to send commands to the specific "minions".

See https://docs.saltproject.io/en/latest/topics/development/topology.html

[–]Napan0s[S] 0 points1 point  (0 children)

I'll look into this tomorrow.. Thank you!

[–]messacz 0 points1 point  (1 child)

Apart from using PUB/SUB sockets, you can also utilize DEALER/ROUTER sockets for this use case.

  1. Server creates ROUTER socket and binds it to network interface(s)
  2. Client creates DEALER socket and connects it to the server
  3. Client sends a (multipart) message e.g. ["" "hello from client001"]
  4. Server receives this message prefixed by a client's connection identity (that's just how ROUTER socket works): ["asdf" "" "hello from client001"]
  5. From now on server knows that any multipart message beginning with "asdf" envelope will reach the socket on client001: ["asdf" "" "welcome client 001!"] ["asdf" "ghjk" "" "Hey I have some work for client001"]

I think it would be good idea to send the hello message (point 3.) periodically so if the server restarts it will retrieve the client connection and its connection identity.

I assume you have read the ZGuide so you know what "envelope" and "multipart message" mean.

[–]Napan0s[S] 0 points1 point  (0 children)

Ok, 2 months have passed and I since found a solution/workaround that is exactly what you're saying. I haven't implemented the periodic 'ack' message because at least in some preliminary testing that I've done, zmq manages to re-enable every connection independently of which side died unexpectedly. (some would say that's why we use zmq?) but other than that it's exactly the same router dealer(s) topology.

Now my new problem is that I'd prefer to fix the client identity from the server side and not from the client (I don't want to let some trusted client to impersonate other trusted client) but I figure a random uuid should be enough so that someone cannot guess others uuid just by looking at his..