#include <nng/transport/tls/tls.h> int nng_tls_register(void);
The tls transport provides communication support between nng sockets across a TCP/IP network using TLS v1.2 on top of TCP. Both IPv4 and IPv6 are supported when the underlying platform also supports it.
The protocol details are documented in TLS Mapping for Scalability Protocols.
Depending upon how the library was built, it may be necessary to
register the transport by calling
The tls transport depends on the use of an external library. As of this writing, mbedTLS version 2.0 or later is required.
|Applications may need to add this library (or libraries) to their link line, particularly when using a statically built nng library.|
This transport uses URIs using the scheme
tls+tcp://, followed by
an IP address or hostname, followed by a colon and finally a
TCP port number.
For example, to contact port 4433 on the localhost
either of the following URIs could be used:
A URI may be restricted to IPv6 using the scheme
tls+tcp6://, and may
be restricted to IPv4 using the scheme
|We recommend using either numeric IP addresses, or names that are specific to either IPv4 or IPv6 to prevent confusion and surprises.|
When specifying IPv6 addresses, the address must be enclosed in
square brackets (
) to avoid confusion with the final colon
separating the port.
For example, the same port 4433 on the IPv6 loopback address ('::1') would
be specified as
|Certificate validation generally works when using names rather than IP addresses. This transport automatically uses the name supplied in the URL when validating the certificate supplied by the server.|
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 (
For example, the following three URIs are all equivalent,
and could be used to listen to port 9999 on the host:
The entire URI must be less than
NNG_MAXADDRLEN bytes long.
The following transport options are available. Note that setting these must be done before the transport is started.
bool) Enable TCP keep-alives, defaults to
bool) Disable Nagle’s algorithm. When enabled (
false), the underlying TCP stream will attempt to buffer and coalesce messages before sending them on, waiting a short interval to improve buffering and reduce the overhead caused by sending too-small messages. This comes at a cost to latency, and is not recommended with modern high speed networks. Defaults to
nng_tls_config *) The underlying TLS configuration object. A hold is placed on the underlying configuration object before returning it. The caller should release the hold with
nng_tls_config_free()when it no longer needs the TLS configuration object.
|Use this option when advanced TLS configuration is required.|
(string) Write-only option naming a file containing certificates to use for peer validation. See
nng_tls_config_ca_file()for more information.
(string) Write-only option naming a file containing the local certificate and associated private key. The private key used must be unencrypted. See
nng_tls_config_own_cert()for more information.
int) Write-only option used to configure the authentication mode used. See
nng_tls_config_auth_mode()for more details.
bool) Whether the remote peer has been properly verified using TLS authentication. May return incorrect results if peer authentication is disabled.