aboutsummaryrefslogtreecommitdiff
path: root/client.py
diff options
context:
space:
mode:
authorSébastien Dailly <sebastien@dailly.me>2023-07-15 14:44:41 +0200
committerSébastien Dailly <sebastien@dailly.me>2023-07-15 14:59:43 +0200
commit02d676bda89c2fb8469ea81f7429c19c1e29df7c (patch)
tree11dae86a561a4800661e6c174b47611a704f857e /client.py
Initial commit
Diffstat (limited to 'client.py')
-rwxr-xr-xclient.py68
1 files changed, 68 insertions, 0 deletions
diff --git a/client.py b/client.py
new file mode 100755
index 0000000..24a8429
--- /dev/null
+++ b/client.py
@@ -0,0 +1,68 @@
+import sys
+from threading import Thread
+from queue import Queue
+import time
+
+#
+# This code provide an example for connecting to the socket server.
+#
+
+from zope import component
+
+from interfaces import endpoint
+component.provideAdapter(endpoint.EndPoint)
+
+from socket_conn import SocketConnection
+conn = SocketConnection()
+
+
+class Conn(Thread):
+
+ def __init__(self, queue):
+ Thread.__init__(self)
+ self.queue = queue
+ self.s = component.queryAdapter(conn, endpoint.IEndpoint)
+ self.s.connect()
+ self.in_queue = Queue()
+ self.s.queue = self.in_queue
+
+ def run(self):
+
+ while True:
+ while not self.queue.empty():
+ text = self.queue.get(False)
+ if text == -1:
+ sys.exit(0)
+ elif text == "":
+ continue
+ self.s.send([{"layout": text}])
+
+ if not self.s.isConnected():
+ time.sleep(2)
+ self.s.connect()
+ continue
+
+
+ self.s.fetch()
+
+ while not self.in_queue.empty():
+ msg = self.in_queue.get(False)
+ print(msg)
+ # Print the promot again
+ print("\n> ", end=u"", flush=True)
+
+ time.sleep(0.2)
+
+queue = Queue()
+c = Conn(queue)
+c.start()
+print("Press ^D to quit")
+while True:
+ try:
+ text = input("> ")
+ queue.put(text)
+ if text == "":
+ continue
+ except:
+ queue.put(-1)
+ break