ZMQ_CONNECT_PEER(3)
π ZMQ_CONNECT_PEER(3) β the 0MQ manual, but make it make sense
okay bestie, sit down, hydrate, because we're talking about zmq_connect_peer β the function that makes an outgoing connection from your socket and hands you back the routing id, all in one thread-safe, atomic little package. no race conditions, no drama, no cap. β¨
β¨ NAME β¨
zmq_connect_peer β create an outgoing connection from a socket and return the connection routing id, in a thread-safe and atomic way. π
πΈ SYNOPSIS πΈ
uint32_t zmq_connect_peer (void *socket, const char *endpoint);
π¦ DESCRIPTION π¦
so zmq_connect_peer() connects a ZMQ_PEER socket to an endpoint and then returns the endpoint's routing_id. that's the whole vibe. it does the connect and gives you the id, atomically, so nobody else can sneak in between. π
the endpoint is a string that looks like transport:// followed by an address. the transport part says which underlying protocol we're using, and the address part says where (in a way that's specific to that transport) we're connecting to. slay.
heads up: this function is supported only on theZMQ_PEERsocket type. anything else and it returns0witherrnoset toENOTSUP. it's giving "wrong socket, bestie." π
and here's the transport lineup zmq_connect_peer() supports:
tcpβ unicast transport using TCP, seezmq_tcp(7)ipcβ local inter-process communication transport, seezmq_ipc(7)inprocβ local in-process (inter-thread) communication transport, seezmq_inproc(7)wsβ unicast transport using WebSockets, seezmq_ws(7)wssβ unicast transport using WebSockets over TLS, seezmq_wss(7)
β RETURN VALUE β
zmq_connect_peer() returns the peer routing_id if it ate. π½οΈ otherwise it returns 0 and sets errno to one of the little guys listed below. periodt.
π₯ ERRORS π₯
EINVALβ the endpoint you supplied is invalid. πEPROTONOSUPPORTβ the requested transport protocol is not supported withZMQ_PEER.ENOCOMPATPROTOβ the requested transport protocol is not compatible with the socket type. it's giving mismatched energy fr fr.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. everyone's busy, bestie. πENOTSUPβ the socket is not of typeZMQ_PEER. (yes, this one again, now with a name.)EFAULTβ theZMQ_IMMEDIATEoption is set on the socket.
π EXAMPLE π
connecting a peer socket to a TCP transport and sending a message. look at her go:
/* 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);
π SEE ALSO π
zmq_connect(3) zmq_bind(3) zmq_socket(3) zmq(7)
π AUTHORS π
this page was written by the 0MQ community. wanna make a change? read the 0MQ Contribution Policy at http://www.zeromq.org/docs:contributing. go off, contribute, main character behavior. π«Ά
okay that's the whole page bestie, you're officially fluent π β¨ this was 0MQ 4.3.5, dated 10/09/2023 β go connect some peers, and remember: thread-safe, atomic, iconic. ππ¦π
π¦ where this page comes from
- epel 10: zeromq 4.3.5-18.el10_0 Β· MPL-2.0 AND BSD-3-Clause AND MIT
- fedora 43: zeromq 4.3.5-22.fc43 Β· MPL-2.0 AND BSD-3-Clause AND MIT
- fedora 43: zeromq 4.3.5-22.fc43 Β· MPL-2.0 AND BSD-3-Clause AND MIT
- fedora 44: zeromq 4.3.5-22.fc43 Β· MPL-2.0 AND BSD-3-Clause AND MIT
- fedora 44: zeromq 4.3.5-22.fc43 Β· MPL-2.0 AND BSD-3-Clause AND MIT
- opensuse-leap 16.0: zeromq-devel 4.3.5-160000.2.2 Β· MPL-2.0
- opensuse-leap 16.0: zeromq-devel 4.3.5-160000.2.2 Β· MPL-2.0
- opensuse-leap 16.0: zeromq-devel 4.3.5-160000.2.2 Β· MPL-2.0
- opensuse-leap 16.0: zeromq-devel 4.3.5-160000.2.2 Β· MPL-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms