2023-10-21 01:50:38 +02:00
|
|
|
= zmq_connect_peer(3)
|
2020-02-09 21:04:56 +01:00
|
|
|
|
|
|
|
|
2023-10-21 01:50:38 +02:00
|
|
|
== NAME
|
2020-02-09 21:04:56 +01:00
|
|
|
zmq_connect_peer - create outgoing connection from socket and return the connection routing id in thread-safe and atomic way.
|
|
|
|
|
|
|
|
|
2023-10-21 01:50:38 +02:00
|
|
|
== SYNOPSIS
|
2020-02-09 21:04:56 +01:00
|
|
|
*uint32_t zmq_connect_peer (void '*socket', const char '*endpoint');*
|
|
|
|
|
|
|
|
|
2023-10-21 01:50:38 +02:00
|
|
|
== DESCRIPTION
|
2020-02-09 21:04:56 +01:00
|
|
|
The _zmq_connect_peer()_ function connects a 'ZMQ_PEER' socket to an 'endpoint' and then returns the endpoint 'routing_id'.
|
|
|
|
|
|
|
|
The 'endpoint' is a string consisting of a 'transport'`://` followed by an
|
|
|
|
'address'. The 'transport' specifies the underlying protocol to use. The
|
|
|
|
'address' specifies the transport-specific address to connect to.
|
|
|
|
|
|
|
|
The function is supported only on the 'ZMQ_PEER' socket type and would return `0` with 'errno' set to 'ENOTSUP' otherwise.
|
|
|
|
|
|
|
|
The _zmq_connect_peer()_ support the following transports:
|
|
|
|
|
2023-10-21 01:50:38 +02:00
|
|
|
'tcp':: unicast transport using TCP, see xref:zmq_tcp.adoc[zmq_tcp]
|
|
|
|
'ipc':: local inter-process communication transport, see xref:zmq_ipc.adoc[zmq_ipc]
|
|
|
|
'inproc':: local in-process (inter-thread) communication transport, see xref:zmq_inproc.adoc[zmq_inproc]
|
|
|
|
'ws':: unicast transport using WebSockets, see xref:zmq_ws.adoc[zmq_ws]
|
|
|
|
'wss':: unicast transport using WebSockets over TLS, see xref:zmq_wss.adoc[zmq_wss]
|
2020-02-09 21:04:56 +01:00
|
|
|
|
2023-10-21 01:50:38 +02:00
|
|
|
== RETURN VALUE
|
2020-02-09 21:04:56 +01:00
|
|
|
The _zmq_connect_peer()_ function returns the peer 'routing_id' if successful. Otherwise it returns
|
|
|
|
`0` and sets 'errno' to one of the values defined below.
|
|
|
|
|
|
|
|
|
2023-10-21 01:50:38 +02:00
|
|
|
== ERRORS
|
2020-02-09 21:04:56 +01:00
|
|
|
*EINVAL*::
|
|
|
|
The endpoint supplied is invalid.
|
|
|
|
*EPROTONOSUPPORT*::
|
|
|
|
The requested 'transport' protocol is not supported with 'ZMQ_PEER'.
|
|
|
|
*ENOCOMPATPROTO*::
|
|
|
|
The requested 'transport' protocol is not compatible with the socket type.
|
|
|
|
*ETERM*::
|
|
|
|
The 0MQ 'context' associated with the specified 'socket' was terminated.
|
|
|
|
*ENOTSOCK*::
|
|
|
|
The provided 'socket' was invalid.
|
|
|
|
*EMTHREAD*::
|
|
|
|
No I/O thread is available to accomplish the task.
|
|
|
|
*ENOTSUP*::
|
|
|
|
The socket is not of type 'ZMQ_PEER'.
|
|
|
|
*EFAULT*::
|
|
|
|
The 'ZMQ_IMMEDIATE' option is set on the socket.
|
|
|
|
|
2023-10-21 01:50:38 +02:00
|
|
|
== EXAMPLE
|
2020-02-09 21:04:56 +01:00
|
|
|
.Connecting a peer socket to a TCP transport and sending a message
|
|
|
|
----
|
|
|
|
/* Create a ZMQ_SUB socket */
|
|
|
|
void *socket = zmq_socket (context, ZMQ_PEER);
|
|
|
|
assert (socket);
|
|
|
|
/* Connect it to the host server001, port 5555 using a TCP transport */
|
|
|
|
uint32_t routing_id = zmq_connect (socket, "tcp://server001:5555");
|
|
|
|
assert (routing_id == 0);
|
|
|
|
/* Sending a message to the peer */
|
|
|
|
zmq_msg_t msg;
|
|
|
|
int rc = zmq_msg_init_data (&msg, "HELLO", 5, NULL, NULL);
|
|
|
|
assert (rc == 0);
|
|
|
|
rc = zmq_msg_set_routing_id (&msg, routing_id);
|
|
|
|
assert (rc == 0);
|
|
|
|
rc = zmq_msg_send (&msg, socket, 0);
|
|
|
|
assert (rc == 5);
|
|
|
|
rc = zmq_msg_close (&msg);
|
|
|
|
assert (rc == 0);
|
|
|
|
----
|
|
|
|
|
|
|
|
|
2023-10-21 01:50:38 +02:00
|
|
|
== SEE ALSO
|
2023-11-03 11:36:47 +01:00
|
|
|
* xref:zmq_connect.adoc[zmq_connect]
|
|
|
|
* xref:zmq_bind.adoc[zmq_bind]
|
|
|
|
* xref:zmq_socket.adoc[zmq_socket]
|
|
|
|
* xref:zmq.adoc[zmq]
|
2020-02-09 21:04:56 +01:00
|
|
|
|
|
|
|
|
2023-10-21 01:50:38 +02:00
|
|
|
== AUTHORS
|
2020-02-09 21:04:56 +01:00
|
|
|
This page was written by the 0MQ community. To make a change please
|
2023-11-22 23:18:23 +01:00
|
|
|
read the 0MQ Contribution Policy at <https://zeromq.org/how-to-contribute/>.
|