NN_CONNECT(3)
π NN_CONNECT(3) π
okay bestie, sit down, we're learning nn_connect from the nanomsg 1.2.2 manual π
this is a section 3 page, so it's a library function, not a command you type in your shell β iykyk π¦
β¨ NAME β¨
nn_connect β add a remote endpoint to the socket πΈ
β¨ SYNOPSIS β¨
#include <nanomsg/nn.h>
int nn_connect (int s, const char *addr);
β¨ DESCRIPTION β¨
So basically: nn_connect adds a remote endpoint to the socket s, and after that the library is gonna try to connect to that remote endpoint for you. no cap, it just does it π«Ά
the addr argument is made of two parts, and they look like this:
transport://address
the transport bit says which underlying transport protocol we're using. the meaning of the address bit? that's specific to whatever transport protocol you picked. so like, don't assume the address format is universal, because it is not β¨
want the list of available transport protocols? go check the list on the nanomsg(7) manual page, bestie π
the maximum length of the addr parameter is specified by NN_SOCKADDR_MAX, which is defined in the <nanomsg/nn.h> header file. keep that in mind or you'll get yelled at (by errno, specifically) π
also!! big one: nn_connect and nn_bind(3) can both be called multiple times on the same socket. that's the whole point, honestly β it lets the socket talk to multiple heterogeneous endpoints at once. main character energy, periodt π
π NOTE π
unlike with traditional BSD sockets, this function operates asynchronously, and it 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 the connection. so don't come crying to me when your first send does nothing, it's literally documented π
and further: the connection may be lost, without any notification to the caller. yeah. no warning, no text, no nothing. BUT β the library will attempt to reconnect automatically in such an event, so that's the slay part π
β¨ RETURN VALUE β¨
if the function succeeds, a positive endpoint ID is returned. π that endpoint ID can be used later to remove the endpoint from the socket via the nn_shutdown(3) function β so like, write it down, bestie π
if the function fails, a negative value is returned and errno is set to one of the values defined below π
β¨ ERRORS β¨
EBADFβ the provided socket is invalid. not a real socket, bestie, it's giving nothing πEMFILEβ maximum number of active endpoints was reached. you hit the ceiling, no more endpoints for you π«EINVALβ the syntax of the supplied address is invalid. you typed it wrong, it happens to the best of us πENAMETOOLONGβ the supplied address is too long. it's giving overachiever, and the system said no πEPROTONOSUPPORTβ the requested transport protocol is not supported. that transport? not on the menu π·ENODEVβ address specifies a nonexistent interface. that interface does not exist, periodt π»ETERMβ the library is terminating. we're shutting down, wrap it up π
β¨ EXAMPLE β¨
s = nn_socket (AF_SP, NN_PUB);
eid1 = nn_connect (s, "ipc:///tmp/test.ipc");
eid2 = nn_connect (s, "tcp://server001:5560");
look at that. two whole endpoints on one socket. iconic behavior honestly π
β¨ SEE ALSO β¨
nn_inproc(7) nn_ipc(7) nn_tcp(7) nn_socket(3) nn_bind(3) nn_shutdown(3) nanomsg(7)
β¨ AUTHORS β¨
Martin Sustrik <sustrik@250bpm.com> and Garrett DβAmore <garrett@damore.org> β thank u legends, we love u π«Άπ
and that's the whole page!! this was the NN_CONNECT(3) manpage from nanomsg, version 1.2.2, dated 2026-01-16 β go forth and connect some endpoints, bestie, u got this πβ¨ππ¦πΈ
π¦ where this page comes from
- fedora 44: nanomsg-devel 1.2.2-2.fc44 Β· MIT
- fedora 44: nanomsg-devel 1.2.2-2.fc44 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms