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, see zmq_tcp(7)
  • ipc β€” local inter-process communication transport, see zmq_ipc(7)
  • inproc β€” local in-process (inter-thread) communication transport, see zmq_inproc(7)
  • pgm, epgm β€” reliable multicast transport using PGM, see zmq_pgm(7)
  • vmci β€” virtual machine communications interface (VMCI), see zmq_vmci(7)
  • udp β€” unreliable unicast and multicast using UDP, see zmq_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 for zmq_bind() and zmq_connect() β€” especially for the tcp, pgm and epgm transports. Do not assume they match, bestie, that's a trap πŸ™ˆ
Note πŸ“Œ following a zmq_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 in zmq_socket(3). By contrast, following a libzmq: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