Commits

Matt Bone  committed ced0020

req/rep client/server

  • Participants

Comments (0)

Files changed (3)

+# use glob syntax.
+syntax: glob
+
+*.elc
+*.pyc
+*~

File reqrepclient.py

+import sys
+import zmq
+
+
+if __name__ == "__main__":
+    if len(sys.argv) != 2:
+        print("usage: reqrepclient.py <zmq_socket>")        
+    zmq_socket = sys.argv[1]
+
+    context = zmq.Context()
+
+    socket = context.socket(zmq.REQ)
+    socket.connect(zmq_socket)
+
+    f = 39.6
+    print("Farenheit: %f" % f)
+    socket.send(str(f))
+    c_str = socket.recv()
+    c = float(c_str)
+
+    print("Celsius: %d" % c)
+    

File reqrepserver.py

+import sys
+import zmq
+
+
+if __name__ == "__main__":
+    if len(sys.argv) != 2:
+        print "usage: reqrepserver.py <zmq_socket>"
+    zmq_socket = sys.argv[1]
+
+    context = zmq.Context()
+
+    socket = context.socket(zmq.REP)
+    print("binding to: %s" % zmq_socket)
+    socket.bind(zmq_socket)
+
+    while True:
+        f = float(socket.recv())
+        print("recv: %f" % f)
+        c = (f - 32.0) * 5.0/9.0
+        socket.send(str(c))