ZMQ_BIND(3)
π ZMQ_BIND(3) β the 0MQ manual, bestie edition π
okay so real talk: this is zmq_bind(3) from the 0MQ Manual. It's the page about β¨acceptingβ¨ incoming connections on a socket. Group chat, gather round π«Ά
β¨ NAME β¨
zmq_bind β accept incoming connections on a socket π
πΈ SYNOPSIS πΈ
int zmq_bind (void *socket, const char *endpoint);
π¦ DESCRIPTION π¦
The zmq_bind() function binds the socket to a local endpoint and then accepts incoming connections on that endpoint. That's it, that's the whole vibe β you pick the spot, you claim the spot, people can now slide into that spot. π
The endpoint is a string made of a transport:// followed by an address. The transport tells you which underlying protocol we're using; the address tells you the transport-specific address to bind to.
0MQ hands you these transports, and honestly, the range? iconic:
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 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 in zmq_socket(3). So like, the exact rules live in that other page, no cap β go read it if you need the specifics π
The ipc, tcp, vmci and udp transports accept wildcard addresses: see zmq_ipc(7), zmq_tcp(7), zmq_vmci(7) and zmq_udp(7) for details. Wildcards = you're not picky about which exact address, and that's valid π
Note π the address syntax may be different forzmq_bind()andzmq_connect()β especially for thetcp,pgmandepgmtransports. Do not assume they match, bestie, that's a trap π
Note π following azmq_bind(), the socket enters a mute state unless or until at least one incoming or outgoing connection is made, at which point the socket enters a ready state. In the mute state, the socket blocks or drops messages according to the socket type, as defined inzmq_socket(3). By contrast, following alibzmq:zmq_connect[3], the socket enters the ready state. So bind = lowkey sitting there waiting π, connect = already in the mix π₯
π RETURN VALUE π
The zmq_bind() function returns zero if successful. Otherwise it returns -1 and sets errno to one of the values defined below. Zero is the slay outcome, -1 means something went wrong and errno will tell you exactly what π΅οΈ
π 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.EADDRINUSEβ the requested address is already in use. Somebody got there first πEADDRNOTAVAILβ the requested address was not local.ENODEVβ the requested address specifies a nonexistent interface.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 β
Binding a publisher socket to an in-process and a TCP transport. Look at her go π§
/* Create a ZMQ_PUB socket */
void *socket = zmq_socket (context, ZMQ_PUB);
assert (socket);
/* Bind it to a in-process transport with the address 'my_publisher' */
int rc = zmq_bind (socket, "inproc://my_publisher");
assert (rc == 0);
/* Bind it to a TCP transport on port 5555 of the 'eth0' interface */
rc = zmq_bind (socket, "tcp://eth0:5555");
assert (rc == 0);
π SEE ALSO π
zmq_connect(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. The community really said "we all wrote this" and honestly? ate π
and that's the page, bestie π«Ά it's from 0MQ 4.3.5 and it's dated 10/09/2023 β go forth and bind 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