1ZMQ_CONNECT_PEER(3)               0MQ Manual               ZMQ_CONNECT_PEER(3)
2
3
4

NAME

6       zmq_connect_peer - create outgoing connection from socket and return
7       the connection routing id in thread-safe and atomic way.
8

SYNOPSIS

10       uint32_t zmq_connect_peer (void *socket, const char *endpoint);
11

DESCRIPTION

13       The zmq_connect_peer() function connects a ZMQ_PEER socket to an
14       endpoint and then returns the endpoint routing_id.
15
16       The endpoint is a string consisting of a transport:// followed by an
17       address. The transport specifies the underlying protocol to use. The
18       address specifies the transport-specific address to connect to.
19
20       The function is supported only on the ZMQ_PEER socket type and would
21       return 0 with errno set to ENOTSUP otherwise.
22
23       The zmq_connect_peer() support the following transports:
24
25       tcp
26           unicast transport using TCP, see zmq_tcp(7)
27
28       ipc
29           local inter-process communication transport, see zmq_ipc(7)
30
31       inproc
32           local in-process (inter-thread) communication transport, see
33           zmq_inproc(7)
34
35       ws
36           unicast transport using WebSockets, see zmq_ws(7)
37
38       wss
39           unicast transport using WebSockets over TLS, see zmq_wss(7)
40

RETURN VALUE

42       The zmq_connect_peer() function returns the peer routing_id if
43       successful. Otherwise it returns 0 and sets errno to one of the values
44       defined below.
45

ERRORS

47       EINVAL
48           The endpoint supplied is invalid.
49
50       EPROTONOSUPPORT
51           The requested transport protocol is not supported with ZMQ_PEER.
52
53       ENOCOMPATPROTO
54           The requested transport protocol is not compatible with the socket
55           type.
56
57       ETERM
58           The 0MQ context associated with the specified socket was
59           terminated.
60
61       ENOTSOCK
62           The provided socket was invalid.
63
64       EMTHREAD
65           No I/O thread is available to accomplish the task.
66
67       ENOTSUP
68           The socket is not of type ZMQ_PEER.
69
70       EFAULT
71           The ZMQ_IMMEDIATE option is set on the socket.
72

EXAMPLE

74       Connecting a peer socket to a TCP transport and sending a message.
75
76           /* Create a ZMQ_SUB socket */
77           void *socket = zmq_socket (context, ZMQ_PEER);
78           assert (socket);
79           /* Connect it to the host server001, port 5555 using a TCP transport */
80           uint32_t routing_id = zmq_connect (socket, "tcp://server001:5555");
81           assert (routing_id == 0);
82           /* Sending a message to the peer  */
83           zmq_msg_t msg;
84           int rc = zmq_msg_init_data (&msg, "HELLO", 5, NULL, NULL);
85           assert (rc == 0);
86           rc = zmq_msg_set_routing_id (&msg, routing_id);
87           assert (rc == 0);
88           rc = zmq_msg_send (&msg, socket, 0);
89           assert (rc == 5);
90           rc = zmq_msg_close (&msg);
91           assert (rc == 0);
92
93

SEE ALSO

95       zmq_connect(3) zmq_bind(3) zmq_socket(3) zmq(7)
96

AUTHORS

98       This page was written by the 0MQ community. To make a change please
99       read the 0MQ Contribution Policy at
100       http://www.zeromq.org/docs:contributing.
101
102
103
1040MQ 4.3.4                         01/30/2021               ZMQ_CONNECT_PEER(3)
Impressum