This documentation is for version v1.3.0 of NNG, but the latest released version is v1.8.0. see the documentation for v1.8.0 for the most up-to-date information.


#include <nng/nng.h>

int nng_stream_listener_listen(nng_stream_listener *l);


The nng_stream_listener_listen() attempts to bind the listener l to the local address specified when the listener was created.

This must generally be done before accepting incoming connections using nng_stream_listener_accept().

For some transports this will also perform other actiosn. For example, with TCP listeners it will configure the underlying port into passive mode, ready to accept an incoming connection, and established a listen queue for receiving incoming connections.

If binding the listener requires allocation of an address (for example when a TCP port number of zero is specified, indicating that an ephemeral port should be used), this operation will allocate that resource. This can permit retrieval of the selected address using nng_stream_listener_get(), typically with the NNG_OPT_LOCADDR option.


This function returns 0 on success, and non-zero otherwise.



The address is already in use.


The address is invalid or unavailable.


The listener has been closed.


The listener is already bound.