Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder7.xlned.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'messages.': 0.04; 'subsequent': 0.04; 'subject:Python': 0.05; 'json': 0.07; 'over,': 0.07; 'python': 0.09; 'length.': 0.09; 'logic': 0.09; 'second.': 0.09; 'cc:addr:python-list': 0.10; 'language': 0.14; '"1.0",': 0.16; '"2":': 0.16; '4-byte': 0.16; 'json,': 0.16; 'roy': 0.16; 'sure.': 0.16; 'unordered': 0.16; 'wrote:': 0.17; 'bytes': 0.17; 'certainly': 0.17; "shouldn't": 0.17; 'feb': 0.19; 'libraries': 0.22; "i'd": 0.22; 'cc:2**0': 0.23; 'statement': 0.23; 'cc:no real name:2**0': 0.24; 'second': 0.24; 'connected': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'am,': 0.27; 'i.e.': 0.27; 'is?': 0.27; 'fixed': 0.28; 'rest': 0.28; 'idea,': 0.29; "i'm": 0.29; 'running': 0.32; 'print': 0.32; '11,': 0.33; 'received:172.16': 0.34; 'server': 0.35; 'protocol': 0.35; 'something': 0.35; 'but': 0.36; 'client': 0.36; 'should': 0.36; 'charset:us-ascii': 0.36; 'possible': 0.37; 'beyond': 0.37; 'why': 0.37; 'sent:': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'application': 0.40; 'first': 0.61; 'header:Message-Id:1': 0.62; 'received:': 0.62; 'between': 0.63; 'messaging': 0.65; 'stuck': 0.65; 'talking': 0.66; 'smith': 0.71; 'dict,': 0.84; 'received:my': 0.93 Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 6.2 \(1499\)) Subject: Re: Python recv loop From: Ihsan Junaidi Ibrahim In-Reply-To: Date: Mon, 11 Feb 2013 22:56:32 +0800 Content-Transfer-Encoding: quoted-printable References: To: Roy Smith X-Mailer: Apple Mail (2.1499) Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 53 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1360594595 news.xs4all.nl 6868 [2001:888:2000:d::a6]:59044 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:38689 Hi Roy, On Feb 11, 2013, at 10:24 AM, Roy Smith wrote: >=20 > Is this server that you're talking to something that you have control=20= > over, i.e. are you stuck with this protocol? Given a choice, I'd go=20= > with something like JSON, for which pre-existing libraries for every=20= > language under the sun. >=20 I'm running JSON for my application messaging protocol but with JSON and = python default unordered dict, there's no guarantee if I put in the length key in the JSON message, it = will be placed on the first bytes hence why it was designed for a fixed 4-byte at the start of the message to = indicate the message length. Beyond the 4-bytes it is all JSON. but if you have a better idea, i would certainly welcome it. > Do you actually *know* what the value of nbuf is? Is it possible that=20= > (somehow) it's 0? You should print (log, whatever), the value of = nbuf,=20 > just to make sure. nbuf is printing the right bytes amount, I removed the print statement = before I made the first post. So to clarify, I added a print statement between the first recv and the = second. {"msgver": "1.0", "msgid": "200", "subcode": "100", "appver": "1.0", = "appid": "1.0", "data": {"1": "igb0", "2": "igb1", "ifcnt": "2"}} connected to misty:8080 sending data 138 bytes sent: 0x86{"msgver": "1.0", "msgid": "200", "subcode": "100", = "appver": "1.0", "appid": "1.0", "data": {"1": "igb0", "2": "igb1", = "ifcnt": "2"}} receiving data message length is 188 0 bytes received: So the subsequent recv() call will be readjusted with 188 bytes buffer = size so theoretically, recv shouldn't return 0. The same logic that I used to send to the server from the python client = that the server will readjust the second recv() call based on the length = information. On this 2nd recv() call the server is able to obtain the = rest of the messages.=