]> gitweb.maison.local Git - my_prox.git/commitdiff
initial commit master
authorlionel <lionel@stargate.enneade.fdn.org>
Fri, 18 Sep 2015 15:43:18 +0000 (17:43 +0200)
committerlionel <lionel@stargate.enneade.fdn.org>
Fri, 18 Sep 2015 15:43:18 +0000 (17:43 +0200)
client.py [new file with mode: 0755]
server.py [new file with mode: 0755]

diff --git a/client.py b/client.py
new file mode 100755 (executable)
index 0000000..5cd2ab3
--- /dev/null
+++ b/client.py
@@ -0,0 +1,27 @@
+#!/usr/bin/python3
+# -*- coding: utf8 -*-
+#
+#   Hello World client in Python
+#   Connects REQ socket to tcp://localhost:5555
+#   Sends "Hello" to server, expects "World" back
+#
+
+import zmq
+
+context = zmq.Context()
+
+#  Socket to talk to server
+print("Connecting to hello world server…")
+socket = context.socket(zmq.REQ)
+#socket.connect("tcp://localhost:5555")
+socket.connect("ipc:///home/lionel/work/python/my_prox/0")
+
+#  Do 10 requests, waiting each time for a response
+for request in range(10):
+    print("Sending request %s â€¦" % request)
+    socket.send(b"Hello")
+
+    #  Get the reply.
+    message = socket.recv()
+    print("Received reply %s [ %s ]" % (request, message))
+
diff --git a/server.py b/server.py
new file mode 100755 (executable)
index 0000000..0de41ee
--- /dev/null
+++ b/server.py
@@ -0,0 +1,28 @@
+#!/usr/bin/python3
+# -*- coding: utf8 -*-
+#
+#   Hello World server in Python
+### Binds REP socket to tcp://*:5555
+#   Binds REP socket to ipc:///home/lionel/work/python/my_prox/0
+#   Expects b"Hello" from client, replies with b"World"
+#
+
+import time
+import zmq
+
+context = zmq.Context()
+socket = context.socket(zmq.REP)
+#socket.bind("tcp://*:5555")
+socket.bind("ipc:///home/lionel/work/python/my_prox/0");
+
+while True:
+    #  Wait for next request from client
+    message = socket.recv()
+    print("Received request: %s" % message)
+
+    #  Do some 'work'
+    time.sleep(1)
+
+    #  Send reply back to client
+    socket.send(b"World")
+