summaryrefslogtreecommitdiffstats
path: root/doc/zmq_remote.py
diff options
context:
space:
mode:
Diffstat (limited to 'doc/zmq_remote.py')
-rwxr-xr-xdoc/zmq_remote.py48
1 files changed, 27 insertions, 21 deletions
diff --git a/doc/zmq_remote.py b/doc/zmq_remote.py
index 155390b..47da520 100755
--- a/doc/zmq_remote.py
+++ b/doc/zmq_remote.py
@@ -12,6 +12,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)
@@ -22,34 +25,37 @@ message_parts = sys.argv[2:]
# first do a ping test
-print("Send ping")
-sock.send("ping".encode())
-data = sock.recv_multipart()
+print("ping")
+sock.send(b"ping")
-if len(data) != 1:
- print("Received invalid number of parts: {}".format(len(data)))
- for i,part in enumerate(data):
- print(" {}".format(part))
- sys.exit(1)
+socks = dict(poller.poll(1000))
+if socks:
+ if socks.get(sock) == zmq.POLLIN:
-if data[0] != b'ok':
- print("Received invalid ping response: {}".format(data.decode()))
- sys.exit(1)
+ 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("Ping ok, sending request '{}'...".format(" ".join(message_parts)))
+ print("Send {}({}): '{}'".format(i, f, part))
-for i, part in enumerate(message_parts):
- if i == len(message_parts) - 1:
- f = 0
- else:
- f = zmq.SNDMORE
+ 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 {} entries:".format(len(data)))
-print(" " + " ".join([d.decode() for d in data]))
+else:
+ print("ZMQ error: timeout")
+ context.destroy(linger=5)
# This is free and unencumbered software released into the public domain.
#