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

NAME

6       zmonitor - 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           zstr_sendx (clientmon, "START", NULL);
78           zsock_wait (clientmon);
79
80           zsock_t *server = zsock_new (ZMQ_DEALER);
81           assert (server);
82           zactor_t *servermon = zactor_new (zmonitor, server);
83           assert (servermon);
84           if (verbose)
85               zstr_sendx (servermon, "VERBOSE", NULL);
86           zstr_sendx (servermon, "LISTEN", "CONNECTED", "DISCONNECTED", NULL);
87           zstr_sendx (servermon, "START", NULL);
88           zsock_wait (servermon);
89
90           //  Allow a brief time for the message to get there...
91           zmq_poll (NULL, 0, 200);
92
93           //  Check client is now listening
94           int port_nbr = zsock_bind (client, "tcp://127.0.0.1:*");
95           assert (port_nbr != -1);
96           s_assert_event (clientmon, "LISTENING");
97
98           //  Check server connected to client
99           zsock_connect (server, "tcp://127.0.0.1:%d", port_nbr);
100           s_assert_event (servermon, "CONNECTED");
101
102           //  Check client accepted connection
103           s_assert_event (clientmon, "ACCEPTED");
104
105           zactor_destroy (&clientmon);
106           zactor_destroy (&servermon);
107           zsock_destroy (&client);
108           zsock_destroy (&server);
109           #endif
110
111

AUTHORS

113       The czmq manual was written by the authors in the AUTHORS file.
114

RESOURCES

116       Main web site:
117
118       Report bugs to the email <zeromq-dev@lists.zeromq.org[1]>
119
121       Copyright (c) the Contributors as noted in the AUTHORS file. This file
122       is part of CZMQ, the high-level C binding for 0MQ:
123       http://czmq.zeromq.org. This Source Code Form is subject to the terms
124       of the Mozilla Public License, v. 2.0. If a copy of the MPL was not
125       distributed with this file, You can obtain one at
126       http://mozilla.org/MPL/2.0/. LICENSE included with the czmq
127       distribution.
128

NOTES

130        1. zeromq-dev@lists.zeromq.org
131           mailto:zeromq-dev@lists.zeromq.org
132
133
134
135CZMQ 4.0.2                        12/31/2016                       ZMONITOR(3)
Impressum