1ZMQ_UNBIND(3) 0MQ Manual ZMQ_UNBIND(3)
2
3
4
6 zmq_unbind - Stop accepting connections on a socket
7
9 int zmq_unbind (void *socket, const char *endpoint);
10
12 The zmq_unbind() function shall unbind a socket specified by the socket
13 argument from the endpoint specified by the endpoint argument.
14
15 Addionally the incoming message queue associated with the endpoint will
16 be discarded. This means that after unbinding an endpoint it is
17 possible to received messages originating from that same endpoint if
18 they were already present in the incoming message queue before
19 unbinding.
20
21 The endpoint argument is as described in zmq_bind(3)
22
23 Unbinding wild-card address from a socket
24 When wild-card * endpoint (described in zmq_tcp(7), zmq_ipc(7),
25 zmq_udp(7) and zmq_vmci(7)) was used in zmq_bind(), the caller should
26 use real endpoint obtained from the ZMQ_LAST_ENDPOINT socket option to
27 unbind this endpoint from a socket.
28
30 The zmq_unbind() function shall return zero if successful. Otherwise it
31 shall return -1 and set errno to one of the values defined below.
32
34 EINVAL
35 The endpoint supplied is invalid.
36
37 ETERM
38 The 0MQ context associated with the specified socket was
39 terminated.
40
41 ENOTSOCK
42 The provided socket was invalid.
43
44 ENOENT
45 The endpoint supplied was not previously bound.
46
48 Unbind a subscriber socket from a TCP transport.
49
50 /* Create a ZMQ_SUB socket */
51 void *socket = zmq_socket (context, ZMQ_SUB);
52 assert (socket);
53 /* Connect it to the host server001, port 5555 using a TCP transport */
54 rc = zmq_bind (socket, "tcp://127.0.0.1:5555");
55 assert (rc == 0);
56 /* Disconnect from the previously connected endpoint */
57 rc = zmq_unbind (socket, "tcp://127.0.0.1:5555");
58 assert (rc == 0);
59
60 Unbind wild-card * binded socket.
61
62 /* Create a ZMQ_SUB socket */
63 void *socket = zmq_socket (context, ZMQ_SUB);
64 assert (socket);
65 /* Bind it to the system-assigned ephemeral port using a TCP transport */
66 rc = zmq_bind (socket, "tcp://127.0.0.1:*");
67 assert (rc == 0);
68 /* Obtain real endpoint */
69 const size_t buf_size = 32;
70 char buf[buf_size];
71 rc = zmq_getsockopt (socket, ZMQ_LAST_ENDPOINT, buf, (size_t *)&buf_size);
72 assert (rc == 0);
73 /* Unbind socket by real endpoint */
74 rc = zmq_unbind (socket, buf);
75 assert (rc == 0);
76
77
79 Note that while the implementation is similar to zmq_disconnect(), the
80 semantics are different and the two functions should not be used
81 interchangeably. Bound sockets should be unbound, and connected sockets
82 should be disconnected.
83
85 zmq_bind(3) zmq_socket(3) zmq(7)
86
88 This page was written by the 0MQ community. To make a change please
89 read the 0MQ Contribution Policy at
90 http://www.zeromq.org/docs:contributing.
91
92
93
940MQ 4.3.4 01/21/2023 ZMQ_UNBIND(3)