nn_bind - Man Page

add a local endpoint to the socket


#include <nanomsg/nn.h>

int nn_bind (int s, const char *addr);


Adds a local endpoint to the socket s. The endpoint can be then used by other applications to connect to.

The addr argument consists of two parts as follows: transport://address. The transport specifies the underlying transport protocol to use. The meaning of the address part is specific to the underlying transport protocol.

For the list of available transport protocols check the list on nanomsg(7) manual page.

Maximum length of the addr parameter is specified by NN_SOCKADDR_MAX defined in <nanomsg/nn.h> header file.

Note that nn_bind and nn_connect(3) may be called multiple times on the same socket thus allowing the socket to communicate with multiple heterogeneous endpoints.


Unlike with traditional BSD sockets, this function operates asynchronously, and returns to the caller before the operation is complete. As a result, attempts to send data or receive data on the socket may not succeed until the underlying transport actually establishes a connection.

Return Value

If the function succeeds positive endpoint ID is returned. Endpoint ID can be later used to remove the endpoint from the socket via nn_shutdown(3) function.

If the function fails, then -1 is returned and errno is set to to one of the values defined below.



The provided socket is invalid.


Maximum number of active endpoints was reached.


The syntax of the supplied address is invalid.


The supplied address is too long.


The requested transport protocol is not supported.


The requested endpoint is not local.


Address specifies a nonexistent interface.


The requested local endpoint is already in use.


The library is terminating.


s = nn_socket (AF_SP, NN_PUB);
eid1 = nn_bind (s, "inproc://test");
eid2 = nn_bind (s, "tcp://");

See Also

nn_inproc(7) nn_ipc(7) nn_tcp(7) nn_socket(3) nn_connect(3) nn_shutdown(3) nanomsg(7)


Martin Sustrik Garrett D’Amore

Referenced By

nanomsg(7), nn_connect(3), nn_inproc(7), nn_ipc(7), nn_shutdown(3), nn_socket(3), nn_tcp(7), nn_ws(7).

2024-01-25 nanomsg 1.1.5