NN_CONNECT(3)

πŸ“¦
version 1.2.2 Β· 5 versions
, in fedora 44

πŸ’– 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