NNG_TCP(7)
π NNG_TCP π
okay bestie, gather round, because we're talking about nng_tcp β the TCP/IP transport from the NNG Reference Manual. this is the one that carries your messages across an actual network, no cap π«Ά
β¨ SYNOPSIS β¨
#include <nng/transport/tcp/tcp.h>
int nng_tcp_register(void);
like, that's the whole vibe. one header, one function π
πΈ DESCRIPTION πΈ
so the tcp transport is literally what lets sockets talk to each other across a TCP/IP network. both IPv4 and IPv6 are supported β whenever the underlying platform also supports them, so it's giving "depends on your OS, babe" π
π¦ Registration π¦
good news: this transport is generally built-in to the core of NNG, so likeβ¦ no extra steps to use it should be necessary. it's already there. it's already iconic. just use it β¨
π URI Format π
URIs here use the scheme tcp://, then an IP address or hostname, then a colon, then finally a TCP port number. the pipeline is: scheme β address β : β port. periodt.
for example, to contact port 80 on the localhost, either of these URIs could be used:
tcp://127.0.0.1:80
tcp://localhost:80
a URI may be restricted to IPv6 using the scheme tcp6://, and may be restricted to IPv4 using the scheme tcp4://.
β οΈ Note: specifying tcp6:// may not prevent IPv4 hosts from being used with IPv4-in-IPv6 addresses, particularly when using a wildcard hostname with listeners. the details of this varies across operating systems. so like, don't @ me, @ your kernel π
β οΈ Note: bothtcp6://andtcp4://are specific to NNG, and might not be understood by other implementations. they're our little thing, iykyk π
π‘ Tip: we recommend using either numeric IP addresses, or names that are specific to either IPv4 or IPv6, to prevent confusion and surprises. no mystery-meat hostnames in this house π
when specifying IPv6 addresses, the address must be enclosed in square brackets ([]) to avoid confusion with the final colon separating the port. like, the colons would be so messy otherwise π
for example, the same port 80 on the IPv6 loopback address (::1) would be specified as:
tcp://[::1]:80
the special value of 0 (INADDR_ANY) can be used for a listener to indicate that it should listen on all interfaces on the host. a short-hand for this form is to either omit the address, or specify the asterisk (*) character. for example, the following three URIs are all equivalent, and could be used to listen to port 9999 on the host:
tcp://0.0.0.0:9999tcp://*:9999tcp://:9999
three different fits, same slay π
the entire URI must be less than NNG_MAXADDRLEN bytes long. that's a hard limit bestie, don't test it π
π§ Socket Address π§
when using an nng_sockaddr structure, the actual structure is either of type nng_sockaddr_in (for IPv4) or nng_sockaddr_in6 (for IPv6). so it's a disguise situation β the generic one is just the wrapper, the real one is underneath π
π Transport Options π
the following transport options are supported by this transport, where supported by the underlying platform:
NNG_OPT_LOCADDRNNG_OPT_REMADDRNNG_OPT_TCP_KEEPALIVENNG_OPT_TCP_NODELAYNNG_OPT_URL
that's the whole menu, no secret items, fr fr β
π₯ SEE ALSO π₯
nng_options(5), nng_sockaddr(5), nng_sockaddr_in(5), nng_sockaddr_in6(5), nng_tcp_options(5), nng(7)
go read those too, they're all bangers π
and that's the whole page, bestie!! this lil ray of sunshine is from the NNG Reference Manual, dated 2026-06-30. you're literally so welcome πβ¨ππ¦πΈπ
π¦ 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