NNG(7)
π NNG π
okay bestie, welcome to nng β nanomsg next generation β and honestly? it's giving foundational. it's the manual page. the mother page. every other page in this reference manual is basically its child. let's get into it π«Ά
β¨ SYNOPSIS β¨
cc ['flags'] 'files' -lnng ['libraries']
that's it. that's the whole ritual. link against -lnng and you're in the group chat π
πΈ DESCRIPTION πΈ
NNG gives you a common messaging framework made to solve the regular, everyday communication problems that pop up in distributed applications. it ships with a bunch of protocols and a bunch of transports, and they are not the same thing, bestie, do not confuse them π
The protocols implement the semantics that go with particular communications scenarios β think RPC style services, service discovery, publish/subscribe, and so on and so forth. β¨
The transports are the support system underneath β TCP, IPC, websockets, you name it, and so forth. π¦
NNG is designed so that making new transports is easy, and making new protocols is also possible, just, y'know, to a lesser extent. we're honest about that here. π
NNG is wire compatible with the SP protocols described in the nanomsg project. that means projects using libnanomsg (<https://github.com/nanomsg/nanomsg>) can inter-operate with nng, and also with any other conforming implementation. (One such implementation is mangos β <https://github.com/go-mangos/mangos>.) π
heads up: applications using NNG that want to talk to other libraries must make sure they only use protocols or transports that the other library actually offers. no cap. otherwise the vibe check fails.
NNG also offers a compatible API, which means legacy code can be recompiled or relinked against NNG. but β and this is the part nobody likes β when you do that, support for certain enhancements or features will likely be absent, and the application developer is gonna have to use the new-style API. it's fine. it's growth. π±
NNG is implemented in pure C, periodt. if you need bindings for other languages, please check the website (<http://nanomsg.org/>). π
π Protocols π
nng_bus(7)β Bus protocol πnng_pair(7)β Pair protocol π―nng_pub(7)β Publisher side of publish/subscribe protocol π’nng_pull(7)β Pull side of pipeline protocol π«³nng_push(7)β Push side of pipeline protocol π«΄nng_sub(7)β Subscriber side of publish/subscribe protocol πnng_rep(7)β Reply side of request/reply protocol β©οΈnng_req(7)β Request side of request/reply protocol β‘οΈnng_respondent(7)β Respondent side of survey protocol πnng_surveyor(7)β Surveyor side of survey protocol π
π¦ Transports π¦
nng_inproc(7)β Intra-process transport π§nng_ipc(7)β Inter-process transport πnng_socket(7)β BSD socket transport π§¦nng_tls(7)β TLSv1.2 over TCP transport πnng_tcp(7)β TCP (and TCPv6) transport πnng_ws(7)β WebSocket transport πΈοΈnng_zerotier(7)β ZeroTier transport β
π Conceptual Overview π
NNG presents a socket view of networking. The sockets are constructed using protocol-specific functions, because a given socket implements precisely one protocol. one socket, one protocol, no polyamory here π«Ά
Each socket can be used to send and receive messages (if the protocol supports it, obviously β read the room), and it implements the appropriate protocol semantics. For example, sub sockets automatically filter incoming messages to discard those for topics that have not been subscribed. iconic behaviour, honestly. β¨
NNG sockets are message oriented, so messages are either delivered wholly, or not at all. Partial delivery is not possible. Furthermore, NNG does not provide any other delivery or ordering guarantees; messages may be dropped or reordered. (Some protocols, such as req, may offer stronger guarantees by performing their own retry and validation schemes. main character protocols π
)
Each socket can have zero, one, or many endpoints, which are either listeners or dialers. (A given socket may freely choose whether it uses listeners, dialers, or both β it's a free country π) These endpoints provide access to underlying transports, such as TCP, etc. π§
Each endpoint is associated with a URL, which is a service address. For dialers, this will be the service address that will be contacted, whereas for listeners this is where the listener will accept new connections. π¬
Endpoints do not themselves transport data. They are instead responsible for the creation of pipes, which can be thought of as message-oriented connected streams. Pipes frequently correspond to a single underlying byte stream β for example, both IPC and TCP transports implement their pipes using a 1:1 relationship with a connected operating system socket. π
Endpoints create pipes as needed. Listeners will create them when a new client connection request arrives, and dialers will generally create one, then wait for it to disconnect before reconnecting. so loyal. so patient. π
Most applications should not have to worry about endpoints or pipes at all; the socket abstraction should provide all the functionality needed, other than in a few specific circumstances. fr fr, don't overthink it.
π Raw Mode π
Most applications will use sockets in normal, or cooked, mode. This mode provides the full semantics of the protocol. For example, req sockets will automatically match a reply to a request, and resend requests periodically if no reply was received. so thoughtful of them π₯Ή
There are situations, such as with proxies, where it is desirable to bypass these semantics and simply pass messages to and from the socket with no extra semantic handling. This is possible using raw mode sockets. π
Raw mode sockets are generally constructed with a different function, such as nng_req0_open_raw(). Using these sockets, the application can simply send and receive messages, and is responsible for supplying any additional socket semantics. Typically this means that the application will need to inspect message headers on incoming messages, and supply them on outgoing messages. you're on your own now, bestie. you got this. πͺ
Tip π‘ The nng_device() function only works with raw mode sockets, but as it only forwards the messages, no additional application processing is needed.
π URLs π
NNG uses universal resource locators (URLs) following the format specified in RFC 3986 (<https://tools.ietf.org/html/rfc3986>), including some schemes that are unique to SP. π¦
The URLs used in NNG are canonicalized as follows, mostly in accordance with RFC 3986 6.2.2 (<https://tools.ietf.org/html/rfc3986#section-6.2.2>):
- The URL is parsed into
scheme,userinfo,host,port,path,queryandfragmentcomponents. (Not all of these members are necessarily present.) π - The scheme, hostname, and port if present, are converted to lower case.
- Percent-encoded values for unreserved characters (
<https://tools.ietf.org/html/rfc3986#section-2.3>) converted to their unencoded forms. - Additionally URL percent-encoded values for characters in the path and with numeric values larger than
127(i.e. not ASCII) are decoded. - The resulting path is checked for invalid UTF-8 sequences, consisting of surrogate pairs, illegal byte sequences, or overlong encodings. If this check fails, then the entire URL is considered invalid. π¨
- Path segments consisting of
.and..are resolved as per RFC 3986 6.2.2.3 (<https://tools.ietf.org/html/rfc3986#section-6.2.2.3>). - Further, empty path segments are removed, meaning that duplicate slash (
/) separators are removed from the path. βοΈ
Note that steps 4, 5, and 7 are not specified by RFC 3986, but performing them is believed to improve both the usability and security of applications, without violating RFC 3986 itself. we're just being extra. responsibly. π
Tip π‘ Port numbers may be service names in some instances, but it is recommended that numeric port numbers be used when known. If service names are used, it is recommended that they follow the naming conventions for C identifiers, and not be longer than 32 characters in length. This will maximize compatibility across systems and minimize opportunities for confusion when they are parsed on different systems. π«Ά
π API π
The library API is documented at libnng(3). go read it. it's good for you. π
π SEE ALSO π
okay that's the whole page, bestie, you ate π
β¨ this was NNG(7) from the NNG Reference Manual, dated 2026-06-30. mwah, go build something cute ππ¦π
π¦ 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