From bfc92fa24ddd8e0057eb1b6a68af334047300162 Mon Sep 17 00:00:00 2001 From: Vincent Le Gallic Date: Tue, 4 Sep 2012 10:20:35 +0200 Subject: [PATCH] =?utf8?q?full=5Fread=20ne=20permettait=20plus=20de=20d?= =?utf8?q?=C3=A9tecter=20un=20serveur=20down?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- client.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/client.py b/client.py index 672ef45..3a72202 100755 --- a/client.py +++ b/client.py @@ -19,15 +19,22 @@ from pprint import pprint sys.path.append(client_config.rsa_path) import monRSA +class DeadServer(Exception): + pass + def full_read(sock): """Lit sur la socket jusqu'à ce que l'output soit déJSON-izable""" output="" + i = 0 while True: output+=sock.read() + i += 1 try: return json.loads(output) except: pass + if i==10 and output=="": + raise DeadServer def connect(sock,where,port=None): if port==None: @@ -84,9 +91,9 @@ def lit(socket): print obj["errmsg"] return obj["msg"] except ssl.SSLError: - return "Rien à lire" - except ValueError: - return "Serveur mort ?" + print "Rien à lire" + except DeadServer: + print "Serveur down ?" if __name__=="__main__": where=raw_input("quel serveur ?") -- 2.39.2