nanomsg next generation NNG  
Home GitHub Documentation

This documentation is for version 0.0.0 of nng, but the latest released version is v1.10.0. see the documentation for v1.10.0 for the most up-to-date information.
libnng(3)

SYNOPSIS

cc [flags] files -lnng [libraries]

DESCRIPTION

The nng(7) library provides a common messaging framework intended to solve common communication problems in distributed applications.

It provides a C language API.

Common Functions

The following common functions exist in libnng.

nng_alloc(3)

allocate memory

nng_dial(3)

create and start a dialer

nng_free(3)

free memory

nng_strerror(3)

return an error description

Socket Functions

The following functions operate on sockets.

nng_close(3)

close a socket

nng_closeall(3)

close all open sockets

nng_dial(3)

create and start a dialer

nng_getopt(3)

get a socket option

nng_listen(3)

create and start a listener

nng_recv(3)

receive data

nng_send(3)

send data

nng_setopt(3)

set a socket option

Message Functions

Applications desiring to use the richest part of libnng will want to use the message API, where a message structure is passed between functions. This API provides the most power support for zero-copy.

Messages are divided into a header and body, where the body generally carries user-payload and the header carries protocol specific header information. Most applications will only interact with the body.

nng_msg_alloc(3)

allocate a message

nng_msg_body(3)

return the message body

nng_msg_free(3)

free a message

nng_msg_header(3)

return the message header

nng_msg_header_len(3)

return the message header length

nng_msg_len(3)

return the message body length

nng_msg_realloc(3)

reallocate a message

nng_recvmsg(3)

receive a message

nng_sendmsg(3)

send a message

Asynchronous Operations

Most applications will interact with nng synchronously; that is that functions such as nng_send() will block the calling thread until the operation has completed.

Synchronous operations which send messages may return before the message has actually been received, or even transmitted. Instead, These functions return as soon as the message was successfully queued for delivery.

Asynchronous operations behave differently. These operations are initiated by the calling thread, but control returns immediately to the calling thread. When the operation is subsequently completed (regardless of whether this was successful or not), then a user supplied function ("callback") is executed.

A context structure, called an aio, is allocated and associated for each asynchronous operation. Only a single asynchronous operation may be associated with an aio at any time.

The following functions are used in the asynchronous model:

nng_aio_alloc(3)

allocate asynchronous I/O context

nng_aio_cancel(3)

cancel asynchronous I/O operation

nng_aio_free(3)

free asynchronous I/O context

nng_aio_get_msg(3)

get message from an asynchronous receive

nng_aio_result(3)

return result from asynchronous operation

nng_aio_stop(3)

stop asynchronous I/O operation

nng_aio_wait(3)

wait for an asynchronous I/O operation

nng_aio_set_msg(3)

set message for an asynchronous send

nng_aio_set_timeout(3)

set timeout for an asynchronous send

nng_recv_aio(3)

receive a message asynchronously

nng_send_aio(3)

send a message asynchronously

Protocols

The following functions are used to construct a socket with a specific protocol:

nng_bus_open(3)

open a bus socket

nng_pair_open(3)

open a pair socket

nng_pub_open(3)

open a pub socket

nng_rep_open(3)

open a rep socket

nng_req_open(3)

open a req socket

nng_respondent_open(3)

open a respondent socket

nng_sub_open(3)

open a sub socket

nng_surveyor_open(3)

open a surveyor socket

Transports

The following functions are used to register a transport for use.

nng_inproc_register(3)

register inproc transport

nng_ipc_register(3)

register IPC transport

nng_tcp_register(3)

register TCP transport

nng_zerotier_register(3)

register ZeroTier transport

Copyright 2017 Garrett D’Amore
Copyright 2017 Capitar IT Group BV

This document is supplied under the terms of the MIT License.

© 2025 Garrett D'Amore and contributors.
nanomsg™ and nng™ are trademarks of Garrett D'Amore.