ZMQ_CONNECT(3)
β¨ ZMQ_CONNECT(3) β¨
okay bestie, welcome to the 0MQ Manual entry for zmq_connect π this is the one where you actually reach out to the world. let's get into it π«Ά
πΈ NAME πΈ
zmq_connect β create outgoing connection from socket
β SYNOPSIS β
int zmq_connect (void *socket, const char *endpoint);
π DESCRIPTION π
so zmq_connect() does the thing where it hooks your socket up to an endpoint and then accepts incoming connections on that endpoint. it's giving "i'm making the first move" energy π₯
the endpoint is a string that looks like transport:// followed by an address. the transport bit says which underlying protocol you're using, and the address bit is the transport-specific address you're connecting to. simple as that π
0MQ ships the following transports, and ngl, they each have their own whole vibe:
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)π§΅pgm,epgmβ reliable multicast transport using PGM, seezmq_pgm(7)π‘vmciβ virtual machine communications interface (VMCI), seezmq_vmci(7)π₯οΈudpβ unreliable unicast and multicast using UDP, seezmq_udp(7)π
every single 0MQ socket type except ZMQ_PAIR and ZMQ_CHANNEL supports one-to-many and many-to-one semantics. the precise semantics depend on the socket type and are defined over in zmq_socket(3). iykyk π
Note π β for most transports and socket types the connection is not performed immediately, but as needed by 0MQ. so a successful call tozmq_connect()does not mean the connection was, or even could actually be, established. because of this, for most transports and socket types, the order in which a server socket is bound and a client socket is connected to it doesn't matter at all. theZMQ_PAIRandZMQ_CHANNELsockets are the exception tho, because they do not automatically reconnect to endpoints π
Note π β following azmq_connect(), for socket types except forZMQ_ROUTER, the socket enters its normal ready state. by contrast, following azmq_bind()alone, the socket enters a mute state in which the socket blocks or drops messages according to the socket type, as defined inzmq_socket(3). aZMQ_ROUTERsocket enters its normal ready state for a specific peer only when handshaking is complete for that peer, and that can take an arbitrary amount of time. main character handshake fr π€
Note π β for some socket types, multiple connections to the same endpoint don't really make sense (seehttps://github.com/zeromq/libzmq/issues/788). for those socket types, any attempt to connect to an already connected endpoint is silently ignored (i.e., returns zero). this behavior applies toZMQ_DEALER,ZMQ_SUB,ZMQ_PUB, andZMQ_REQsocket types. no drama, no error, just vibes π
π RETURN VALUE π
zmq_connect() returns zero if it slays. otherwise it returns -1 and sets errno to one of the values defined below π
π₯ ERRORS π₯
EINVALβ the endpoint supplied is invalid.EPROTONOSUPPORTβ the requested transport protocol is not supported.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.
π EXAMPLE π
connecting a subscriber socket to an in-process and a TCP transport. iconic behavior honestly β¨
/* Create a ZMQ_SUB socket */
void *socket = zmq_socket (context, ZMQ_SUB);
assert (socket);
/* Connect it to an in-process transport with the address 'my_publisher' */
int rc = zmq_connect (socket, "inproc://my_publisher");
assert (rc == 0);
/* Connect it to the host server001, port 5555 using a TCP transport */
rc = zmq_connect (socket, "tcp://server001:5555");
assert (rc == 0);
π SEE ALSO π
zmq_bind(3) zmq_socket(3) zmq(7)
π AUTHORS π
this page was written by the 0MQ community π«Ά to make a change please read the 0MQ Contribution Policy at http://www.zeromq.org/docs:contributing.
and that's the whole page bestie, you ate π this was 0MQ 4.3.5, dated 10/09/2023 β go forth and connect responsibly π¦πΈ
π¦ 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