1NN_CONNECT(3) nanomsg 1.1.5 NN_CONNECT(3)
2
3
4
6 nn_connect - add a remote endpoint to the socket
7
9 #include <nanomsg/nn.h>
10
11 int nn_connect (int s, const char *addr);
12
14 Adds a remote endpoint to the socket s. The library would then try to
15 connect to the specified remote endpoint.
16
17 The addr argument consists of two parts as follows:
18 transport://address. The transport specifies the underlying transport
19 protocol to use. The meaning of the address part is specific to the
20 underlying transport protocol.
21
22 For the list of available transport protocols check the list on
23 nanomsg(7) manual page.
24
25 Maximum length of the addr parameter is specified by NN_SOCKADDR_MAX
26 defined in <nanomsg/nn.h> header file.
27
28 Note that nn_connect and nn_bind(3) may be called multiple times on the
29 same socket thus allowing the socket to communicate with multiple
30 heterogeneous endpoints.
31
33 Unlike with traditional BSD sockets, this function operates
34 asynchronously, and returns to the caller before the operation is
35 complete. As a result, attempts to send data or receive data on the
36 socket may not succeed until the underlying transport actually
37 establishes the connection. Further, the connection may be lost,
38 without any notification to the caller. The library will attempt to
39 reconnect automatically in such an event.
40
42 If the function succeeds positive endpoint ID is returned. Endpoint ID
43 can be later used to remove the endpoint from the socket via
44 nn_shutdown(3) function.
45
46 If the function fails negative value is returned and errno is set to to
47 one of the values defined below.
48
50 EBADF
51 The provided socket is invalid.
52
53 EMFILE
54 Maximum number of active endpoints was reached.
55
56 EINVAL
57 The syntax of the supplied address is invalid.
58
59 ENAMETOOLONG
60 The supplied address is too long.
61
62 EPROTONOSUPPORT
63 The requested transport protocol is not supported.
64
65 ENODEV
66 Address specifies a nonexistent interface.
67
68 ETERM
69 The library is terminating.
70
72 s = nn_socket (AF_SP, NN_PUB);
73 eid1 = nn_connect (s, "ipc:///tmp/test.ipc");
74 eid2 = nn_connect (s, "tcp://server001:5560");
75
77 nn_inproc(7) nn_ipc(7) nn_tcp(7) nn_socket(3) nn_bind(3) nn_shutdown(3)
78 nanomsg(7)
79
81 Martin Sustrik <sustrik@250bpm.com> Garrett D’Amore
82 <garrett@damore.org>
83
84
85
86 2021-07-22 NN_CONNECT(3)