diff options
Diffstat (limited to 'doc')
-rwxr-xr-x | doc/zmq-ctrl/zmq_remote.py | 42 |
1 files changed, 27 insertions, 15 deletions
diff --git a/doc/zmq-ctrl/zmq_remote.py b/doc/zmq-ctrl/zmq_remote.py index 3a54b20..9e49b82 100755 --- a/doc/zmq-ctrl/zmq_remote.py +++ b/doc/zmq-ctrl/zmq_remote.py @@ -7,6 +7,9 @@ context = zmq.Context() sock = context.socket(zmq.REQ) +poller = zmq.Poller() +poller.register(sock, zmq.POLLIN) + if len(sys.argv) < 2: print("Usage: program url cmd [args...]") sys.exit(1) @@ -19,24 +22,33 @@ message_parts = sys.argv[2:] print("ping") sock.send(b"ping") -data = sock.recv_multipart() -print("Received: {}".format(len(data))) -for i,part in enumerate(data): - print(" {}".format(part)) -for i, part in enumerate(message_parts): - if i == len(message_parts) - 1: - f = 0 - else: - f = zmq.SNDMORE +socks = dict(poller.poll(1000)) +if socks: + if socks.get(sock) == zmq.POLLIN: + + data = sock.recv_multipart() + print("Received: {}".format(len(data))) + for i,part in enumerate(data): + print(" {}".format(part)) + + for i, part in enumerate(message_parts): + if i == len(message_parts) - 1: + f = 0 + else: + f = zmq.SNDMORE + + print("Send {}({}): '{}'".format(i, f, part)) - print("Send {}({}): '{}'".format(i, f, part)) + sock.send(part.encode(), flags=f) - sock.send(part.encode(), flags=f) + data = sock.recv_multipart() -data = sock.recv_multipart() + print("Received: {}".format(len(data))) + for i,part in enumerate(data): + print(" RX {}: {}".format(i, part)) -print("Received: {}".format(len(data))) -for i,part in enumerate(data): - print(" RX {}: {}".format(i, part)) +else: + print("ZMQ error: timeout") + context.destroy(linger=5) |