NNG_PAIR(7)
β¨ NNG_PAIR(7) β¨
okay bestie, welcome to the NNG Reference Manual page for nng_pair π this is the pair protocol and it's genuinely one of the cutest little patterns in the whole library, no cap.
πΈ NAME πΈ
nng_pair β the pair protocol π«Ά
π SYNOPSIS π
so depending on which version you're on, you're gonna grab a different header, okay? don't mix them up, i'm begging π
Version 0
#include <nng/protocol/pair0/pair.h>
Version 1
#include <nng/protocol/pair1/pair.h>
π DESCRIPTION π
The pair protocol implements a peer-to-peer pattern, where relationships between peers are one-to-one. like, literally a duo. a two-person group chat. iconic.
π¦ Socket Operations π¦
The nng_pair_open() functions create a pair socket. that's your entry point, bestie β¨
Normally, this pattern will block when attempting to send a message if no peer is able to receive the message. it's not ghosting you, it's just waiting π
Note π¨ Even though this mode may appear to be reliable β because back-pressure prevents discarding messages most of the time β there are topologies involving devices (seenng_device()) or raw mode sockets (seeNNG_OPT_RAW) where messages may be discarded. π Applications that require reliable delivery semantics should consider usingreqsockets, or implement their own acknowledgment layer on top of pair sockets. periodt.
π Protocol Versions π
Version 0 is the legacy version of this protocol. It lacks any header information, and is suitable when building simple one-to-one topologies.
Tip π‘ Use version 0 if you need to communicate with other implementations, including the legacynanomsg(https://github.com/nanomsg/nanomsg) library ormangos(https://github.com/go-mangos/mangos). iykyk.
Version 1 of the protocol offers improved protection against loops when used with nng_device(). glow up fr fr β¨
π Polyamorous Mode π
Warning β οΈ Polyamorous mode is deprecated, and support for it will likely be removed in a future release. Applications are strongly discouraged from making further use of it. like, it's giving "we're breaking up eventually", bestie. π
Normally pair sockets are for one-to-one communication, and a given peer will reject new connections if it already has an active connection to another peer. exclusive vibes only π ββοΈ
Polyamorous mode changes this, to allow a socket to communicate with multiple directly-connected peers. This mode is enabled by opening a socket with the nng_pair1_open_poly() function β¨
Note πΈ Polyamorous mode is only available when using pair version 1.
In polyamorous mode a socket can support many one-to-one connections. In this mode, the application must choose the remote peer to receive an outgoing message by setting the nng_pipe to use for the outgoing message with the nng_msg_set_pipe() function. you're picking the main character of this message, bestie π
If no remote peer is specified by the sender, then the protocol will select any available connected peer. dealer's choice, literally π²
Most often the value of the outgoing pipe will be obtained from an incoming message using the nng_msg_get_pipe() function, such as when replying to an incoming message. yes, you caught it from the incoming vibe and you're sending it right back β¨
Note π Directed send only works with directly connected peers. It will not function across device proxies.
In order to prevent head-of-line blocking, if the peer on the given pipe is not able to receive (or the pipe is no longer available, such as if the peer has disconnected), then the message will be discarded with no notification to the sender. ποΈ no receipt, no read, nothing. gone.
π Protocol Options π
The following protocol-specific options are available:
NNG_OPT_MAXTTLβ (int, version 1 only). Maximum time-to-live. your message's lil expiration date π«ΆNNG_OPT_PAIR1_POLYβ (bool, version 1 only). This option is no longer supported. Formerly it was used to configure polyamorous mode, but that mode is now established by using thenng_pair1_open_poly()function. it's retired bestie, we don't use it anymore π
π§ Protocol Headers π§
Version 0 of the pair protocol has no protocol-specific headers. clean face, no makeup β¨
Version 1 of the pair protocol uses a single 32-bit unsigned value. The low-order (big-endian) byte of this value contains a "hop" count, and is used in conjunction with the NNG_OPT_MAXTTL option to guard against device forwarding loops. This value is initialized to 1, and incremented each time the message is received by a new node. cute lil hop counter, keeping the loops from happening π¦
π SEE ALSO π
and that's the whole page, bestie!! π this was NNG_PAIR(7) from the NNG Reference Manual, dated 2026-06-30 π go forth and pair responsibly, mwah ππ
π«Ά
π¦ where this page comes from
- ubuntu stonking: libnng-dev 1.12.0-1 Β· MIT OR Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms