NN_REQREP(7)

πŸ“¦
version 1.2.2 Β· 5 versions
, in fedora 44

πŸ’Œ NN_REQREP β€” the request/reply protocol, bestie edition πŸ’Œ

okay so this is nn_reqrep(7) from nanomsg 1.2.2, and it's literally the blueprint for making a bunch of stateless workers share the workload. no cap. let's get into it 🫢


✨ NAME ✨

nn_reqrep β€” the request/reply scalability protocol πŸ’…

🌸 SYNOPSIS 🌸

#include <nanomsg/nn.h>

#include <nanomsg/reqrep.h>

that's it. two includes. iconic behavior honestly.


πŸ¦‹ DESCRIPTION πŸ¦‹

so the whole point of this protocol is to distribute the workload among multiple stateless workers. that's the vibe. that's the assignment. ✨

heads up bestie: request/reply applications should be stateless. like, actually. this is not a suggestion, this is the whole design.

and it's important β€” like, key β€” to include all the info you need to process the request inside the request itself. yes, including info about the sender or the originator of the request, if you need that to be able to respond. πŸŽ€

because here's the thing: sender information cannot be retrieved from the underlying socket connection. and there's two reasons, both real:

  • first, transports like IPC may not have a firm notion of a message origin. like, the concept just isn't there. πŸ’€
  • second, transports that do have some notion may not have a reliable one β€” a TCP disconnect might mean a brand new sender, or it might just mean a temporary loss in network connectivity. and you literally cannot tell which. πŸ™ˆ

so for this reason, sender information must be included by the application if it's required. the manpage says: allocating 6 randomly-generated bytes in the message for the lifetime of the connection is sufficient for most purposes. and if your app is longer-lived? an UUID is more suitable. 🌈


🧚 Socket Types 🧚

  • NN_REQ β€” the one you use to implement the client application that sends requests and receives replies. main character energy, obviously. πŸ‘‘
  • NN_REP β€” the one you use to implement the stateless worker that receives requests and sends replies. the backbone fr fr. πŸ’ͺ

πŸ’… Socket Options πŸ’…

  • NN_REQ_RESEND_IVL β€” this option is defined on the full REQ socket. if a reply isn't received within the specified amount of milliseconds, the request gets automatically resent. type of this option is int. default value is 60000 (that's 1 minute, bestie). ⏰πŸ”₯

⭐ SEE ALSO ⭐

nn_bus(7) nn_pubsub(7) nn_pipeline(7) nn_survey(7) nn_pair(7) nanomsg(7)

go read them all, they're all slay in their own way. πŸ“šβœ¨


πŸ‘‘ AUTHORS πŸ‘‘

Martin Sustrik <sustrik@250bpm.com> β€” thank you for your service, king πŸ«‘πŸ’–


and that's the whole page!! this was nanomsg 1.2.2, dated 2026-01-16, and honestly? obsessed. go build something stateless and gorgeous. mwah πŸ’‹πŸ’–βœ¨

πŸ“¦ where this page comes from