nn_device - start a device
int nn_device (int s1, int s2);
Starts a device to forward messages between two sockets. If both sockets are
function loops and sends any messages received from
and vice versa. If only one socket is valid and the
other is negative, nn_device
works in a "loopback" mode
— it loops and sends any messages received from the socket back to
To break the loop and make nn_device
function exit use the nn_term(3)
The function loops until it hits an error. In such a case it returns -1 and sets
to one of the values defined below.
One of the provided sockets is invalid.
Either one of the socket is not an AF_SP_RAW socket; or
the two sockets don’t belong to the same protocol; or the
directionality of the sockets doesn’t fit (e.g. attempt to join two
SINK sockets to form a device).
The operation was interrupted by delivery of a
The library is terminating.
int s1 = nn_socket (AF_SP_RAW, NN_REQ);
nn_bind (s1, "tcp://127.0.0.1:5555");
int s2 = nn_socket (AF_SP_RAW, NN_REP);
nn_bind (s2, "tcp://127.0.0.1:5556");
nn_device (s1, s2);
nn_socket(3) nn_term(3) nanomsg(7)