Commits

Matt Bone committed 2c8d2d7

adding push pull example

  • Participants
  • Parent commits ced0020

Comments (0)

Files changed (2)

pushpullclient.py

+import sys
+import zmq
+
+
+if __name__ == "__main__":
+    if len(sys.argv) != 2:
+        print("usage: pushpullclient.py <zmq_socket>")        
+    zmq_socket = sys.argv[1]
+
+    context = zmq.Context()
+
+    socket = context.socket(zmq.PULL)
+    socket.connect(zmq_socket)
+
+    while True:
+        json_blob = socket.recv_json()
+        print json_blob
+    

pushpullserver.py

+import sys
+import datetime
+import time
+import zmq
+
+
+if __name__ == "__main__":
+    if len(sys.argv) != 2:
+        print "usage: pushpullserver.py <zmq_socket>"
+    zmq_socket = sys.argv[1]
+
+    context = zmq.Context()
+
+    socket = context.socket(zmq.PUSH)
+    print("binding to: %s" % zmq_socket)
+    socket.bind(zmq_socket)
+
+    count = 0
+    while True:
+        now = str(datetime.datetime.now())
+
+        print "send #%s" % count
+        socket.send_json({'timestamp': now,
+                          'count': count})
+        count += 1
+        time.sleep(1)