This patch adds code to check to make sure that the whole json string is received before sending it to simplejson.loads().
Thanks, Aaron -- Aaron O. Rosen Masters Student - Network Communication 306B Fluor Daniel
From 563668458bd66b5d7add41deaeb467519b7a60f6 Mon Sep 17 00:00:00 2001 From: Aaron Rosen <aro...@clemson.edu> Date: Wed, 21 Sep 2011 21:21:49 -0400 Subject: [PATCH] This code now checks to make sure that we have received balanced { } before trying to print and decode the json. If we have not yet receieve the full string we keep looping until we do. --- src/scripts/nox-console.py | 15 ++++++++++++++- 1 files changed, 14 insertions(+), 1 deletions(-) diff --git a/src/scripts/nox-console.py b/src/scripts/nox-console.py index 17054f9..e138342 100755 --- a/src/scripts/nox-console.py +++ b/src/scripts/nox-console.py @@ -101,7 +101,20 @@ if (debug): print simplejson.dumps(cmd) sock.send(simplejson.dumps(cmd)) if (expectReply): - print simplejson.dumps(simplejson.loads(sock.recv(4096)), indent=4) + data="" + while True: + data += sock.recv(4096) + LeftBracket=0 + RightBracket=0 + for i in data: + if i == '}': + LeftBracket +=1 + elif i == '{': + RightBracket +=1 + if LeftBracket == RightBracket: + print simplejson.dumps(simplejson.loads(data), indent=4) + break + sock.send("{\"type\":\"disconnect\"}") sock.shutdown(1) sock.close() -- 1.7.3.4
_______________________________________________ nox-dev mailing list nox-dev@noxrepo.org http://noxrepo.org/mailman/listinfo/nox-dev