From 8207a45654d8808a6eff03195fc25abc81c7d2b7 Mon Sep 17 00:00:00 2001 From: Brendan Howell Date: Sat, 13 Feb 2016 00:19:13 +0100 Subject: [PATCH] kbtest resets connections after timeout --- screenless/bureau/kbtest.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/screenless/bureau/kbtest.py b/screenless/bureau/kbtest.py index 8a4de70..21f0205 100644 --- a/screenless/bureau/kbtest.py +++ b/screenless/bureau/kbtest.py @@ -1,9 +1,24 @@ +import time + import zmq ctx = zmq.Context() -send = ctx.socket(zmq.PUB) -send.connect("tcp://localhost:10100") while True: msg = input("> ") - send.send_string(msg) + send = ctx.socket(zmq.REQ) + send.connect("ipc://.screenless/" + msg[0:2] + ".ipc") + send.send_string(msg[2:]) + print("sending ", msg[2:]) + ret = None + trys = 0 + while (not ret) and (trys < 10): + try: + ret = send.recv(flags=zmq.NOBLOCK) + print("got", ret) + except zmq.ZMQError: + trys += 1 + time.sleep(0.05) + if not ret: + print("Error: timeout after 0.5 sec") + send.close()