NNG_TCP(7)

πŸ“¦
version 1.12.0 Β· 4 versions
, in ubuntu stonking

πŸ’– 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: both tcp6:// and tcp4:// 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:

  1. tcp://0.0.0.0:9999
  2. tcp://*:9999
  3. tcp://: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_LOCADDR
  • NNG_OPT_REMADDR
  • NNG_OPT_TCP_KEEPALIVE
  • NNG_OPT_TCP_NODELAY
  • NNG_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