Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

zserve (and client) prototype

  • Loading branch information...
commit bb7adb3bfcb2bfc30ae5dd75852ebde0294276ce 1 parent db576f3
@arsatiki authored
Showing with 46 additions and 1 deletion.
  1. +0 −1  README.rst
  2. +21 −0 reqping.py
  3. +25 −0 zserve.py
View
1  README.rst
@@ -27,7 +27,6 @@ and energy permit, I will convert them to C.
TODO
----
-- Prototype ZMQ Serve
- `setup.py` and commands as egg entrypoints
- Tests
- `getopt`
View
21 reqping.py
@@ -0,0 +1,21 @@
+import sys
+import zmq
+
+def main(addr, sender):
+ """foo"""
+
+ ctx = zmq.Context()
+ socket = ctx.socket(zmq.REQ)
+ socket.connect(addr)
+
+ k = 0
+ while True:
+ socket.send("Message %d from %s" % (k, sender))
+ print socket.recv()
+ k += 1
+
+ socket.close()
+
+
+if __name__ == '__main__':
+ main(sys.argv[1], sys.argv[2])
View
25 zserve.py
@@ -0,0 +1,25 @@
+from subprocess import Popen, PIPE
+import sys
+
+import zmq
+
+def main(addr, cmd):
+ """foo"""
+
+ ctx = zmq.Context()
+ socket = ctx.socket(zmq.REP)
+ socket.bind(addr)
+
+ while True:
+ # Not line by line ATM.
+ # It'd be nice but probably not sane.
+ proc = Popen(cmd, bufsize=1, stdin=PIPE, stdout=PIPE)
+ input = socket.recv() # XXX Multiparts?
+ output, _ = proc.communicate(input)
+ socket.send(output)
+
+ socket.close()
+
+
+if __name__ == '__main__':
+ main(sys.argv[1], sys.argv[2:])
Please sign in to comment.
Something went wrong with that request. Please try again.