1ZMONITOR(3)                       CZMQ Manual                      ZMONITOR(3)
2
3
4

NAME

6       zmonitor - Class for socket event monitor
7

SYNOPSIS

9       //  Create new zmonitor actor instance to monitor a zsock_t socket:
10       //
11       //      zactor_t *monitor = zactor_new (zmonitor, mysocket);
12       //
13       //  Destroy zmonitor instance.
14       //
15       //      zactor_destroy (&monitor);
16       //
17       //  Enable verbose logging of commands and activity.
18       //
19       //      zstr_send (monitor, "VERBOSE");
20       //
21       //  Listen to monitor event type (zero or types, ending in NULL):
22       //      zstr_sendx (monitor, "LISTEN", type, ..., NULL);
23       //
24       //      Events:
25       //      CONNECTED
26       //      CONNECT_DELAYED
27       //      CONNECT_RETRIED
28       //      LISTENING
29       //      BIND_FAILED
30       //      ACCEPTED
31       //      ACCEPT_FAILED
32       //      CLOSED
33       //      CLOSE_FAILED
34       //      DISCONNECTED
35       //      MONITOR_STOPPED
36       //      ALL
37       //
38       //  Start monitor; after this, any further LISTEN commands are ignored.
39       //
40       //      zstr_send (monitor, "START");
41       //      zsock_wait (monitor);
42       //
43       //  Receive next monitor event:
44       //
45       //      zmsg_t *msg = zmsg_recv (monitor);
46       //
47       //  This is the zmonitor constructor as a zactor_fn; the argument can be
48       //  a zactor_t, zsock_t, or libzmq void * socket:
49       CZMQ_EXPORT void
50           zmonitor (zsock_t *pipe, void *sock);
51
52       //  Selftest
53       CZMQ_EXPORT void
54           zmonitor_test (bool verbose);
55       Please add '@interface' section in './../src/zmonitor.c'.
56

DESCRIPTION

58       The zmonitor actor provides an API for obtaining socket events such as
59       connected, listen, disconnected, etc. Socket events are only available
60       for sockets connecting or bound to ipc:// and tcp:// endpoints.
61
62       This class wraps the ZMQ socket monitor API, see zmq_socket_monitor for
63       details. Works on all versions of libzmq from 3.2 onwards. This class
64       replaces zproxy_v2, and is meant for applications that use the CZMQ v3
65       API (meaning, zsock).
66

EXAMPLE

68       From zmonitor_test method.
69
70           zsock_t *client = zsock_new (ZMQ_DEALER);
71           assert (client);
72           zactor_t *clientmon = zactor_new (zmonitor, client);
73           assert (clientmon);
74           if (verbose)
75               zstr_sendx (clientmon, "VERBOSE", NULL);
76           zstr_sendx (clientmon, "LISTEN", "LISTENING", "ACCEPTED", NULL);
77           #if defined (ZMQ_EVENT_HANDSHAKE_SUCCEED)
78           zstr_sendx (clientmon, "LISTEN", "HANDSHAKE_SUCCEED", NULL);
79           #endif
80           #if defined (ZMQ_EVENT_HANDSHAKE_SUCCEEDED)
81           zstr_sendx (clientmon, "LISTEN", "HANDSHAKE_SUCCEEDED", NULL);
82           #endif
83           zstr_sendx (clientmon, "START", NULL);
84           zsock_wait (clientmon);
85
86           zsock_t *server = zsock_new (ZMQ_DEALER);
87           assert (server);
88           zactor_t *servermon = zactor_new (zmonitor, server);
89           assert (servermon);
90           if (verbose)
91               zstr_sendx (servermon, "VERBOSE", NULL);
92           zstr_sendx (servermon, "LISTEN", "CONNECTED", "DISCONNECTED", NULL);
93           zstr_sendx (servermon, "START", NULL);
94           zsock_wait (servermon);
95
96           //  Allow a brief time for the message to get there...
97           zmq_poll (NULL, 0, 200);
98
99           //  Check client is now listening
100           int port_nbr = zsock_bind (client, "tcp://127.0.0.1:*");
101           assert (port_nbr != -1);
102           s_assert_event (clientmon, "LISTENING");
103
104           //  Check server connected to client
105           zsock_connect (server, "tcp://127.0.0.1:%d", port_nbr);
106           s_assert_event (servermon, "CONNECTED");
107
108           //  Check client accepted connection
109           s_assert_event (clientmon, "ACCEPTED");
110           #if defined (ZMQ_EVENT_HANDSHAKE_SUCCEED)
111           s_assert_event (clientmon, "HANDSHAKE_SUCCEED");
112           #endif
113           #if defined (ZMQ_EVENT_HANDSHAKE_SUCCEEDED)
114           s_assert_event (clientmon, "HANDSHAKE_SUCCEEDED");
115           #endif
116
117           zactor_destroy (&clientmon);
118           zactor_destroy (&servermon);
119           zsock_destroy (&client);
120           zsock_destroy (&server);
121
122           #if defined (__WINDOWS__)
123           zsys_shutdown();
124           #endif
125
126

AUTHORS

128       The czmq manual was written by the authors in the AUTHORS file.
129

RESOURCES

131       Main web site:
132
133       Report bugs to the email <zeromq-dev@lists.zeromq.org[1]>
134
136       Copyright (c) the Contributors as noted in the AUTHORS file. This file
137       is part of CZMQ, the high-level C binding for 0MQ:
138       http://czmq.zeromq.org. This Source Code Form is subject to the terms
139       of the Mozilla Public License, v. 2.0. If a copy of the MPL was not
140       distributed with this file, You can obtain one at
141       http://mozilla.org/MPL/2.0/. LICENSE included with the czmq
142       distribution.
143

NOTES

145        1. zeromq-dev@lists.zeromq.org
146           mailto:zeromq-dev@lists.zeromq.org
147
148
149
150CZMQ 4.2.1                        10/31/2019                       ZMONITOR(3)
Impressum