Path: csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.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; 'subject:Python': 0.05; 'mrab': 0.05; 'say,': 0.05; 'happen,': 0.07; 'json': 0.07; 'bytes,': 0.09; 'iterate': 0.09; 'length.': 0.09; 'loop.': 0.09; "wouldn't": 0.11; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'integer.': 0.16; 'wrote:': 0.17; '>>>': 0.18; 'feb': 0.19; 'code.': 0.20; 'followed': 0.20; 'sort': 0.21; "i'd": 0.22; 'insert': 0.23; 'header:In-Reply-To:1': 0.25; '(which': 0.26; 'am,': 0.27; 'guess': 0.27; 'message-id:@mail.gmail.com': 0.27; 'fixed': 0.28; 'chris': 0.28; 'decimal': 0.29; 'character': 0.29; 'probably': 0.29; '11,': 0.33; 'retain': 0.33; 'to:addr :python-list': 0.33; 'received:google.com': 0.34; 'pm,': 0.35; 'received:209.85': 0.35; 'but': 0.36; '12,': 0.36; 'received:209': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'space': 0.39; 'your': 0.60; 'first': 0.61; 'between': 0.63; 'ever': 0.63; 'more': 0.63; '2013': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=eMzKGpgo4bsJ3qQHuOzpAlVC3khWLIxPugY9uATaiEE=; b=r8Cof/uwe4ROGNWsY/UXt8aewVamyXQiqjdAJ7OmSBeVKnsu1SkYdSzBLEP0inn/Yv pqVQ7BXgoQSx+TZkAD72P+t+ilMjmr/QZS3lgXpgvXWSBbrN1oWWG0T3dT3V1zgFmocz Lzsz4FH0wIs9aZvQjs5jzKVO1Lrg3s8anpTXBLnj4BAKRHr/Jxi/O+fjx+3/UPAC6j3R UM+ks5QTWX/XOEBe/veDLiRrrq8/2uXxZWFdyU2Pq8I7s9vpeMl5TXKxbfRnSm6nH8Ed NaPJU7kV790gfSMuZzUblB4OaANPlQ4Ld6KZpC5Vto7fv+aYL77X96aSe3FJwf/nhJz9 dvmQ== MIME-Version: 1.0 X-Received: by 10.220.149.200 with SMTP id u8mr21889974vcv.7.1360635632030; Mon, 11 Feb 2013 18:20:32 -0800 (PST) In-Reply-To: <6F9402BA-4753-4543-A8E7-05E5234660EA@grep.my> References: <51190A32.7070105@mrabarnett.plus.com> <6F9402BA-4753-4543-A8E7-05E5234660EA@grep.my> Date: Tue, 12 Feb 2013 13:20:31 +1100 Subject: Re: Python recv loop From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 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: 23 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1360635633 news.xs4all.nl 6852 [2001:888:2000:d::a6]:34471 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:38715 On Tue, Feb 12, 2013 at 12:41 PM, Ihsan Junaidi Ibrahim wrote: > > On Feb 11, 2013, at 11:24 PM, Chris Angelico wrote: > >> On Tue, Feb 12, 2013 at 2:11 AM, MRAB wrote: >>> I probably wouldn't make it fixed length. I'd have the length in >>> decimal followed by, say, "\n". >> >> Or even "followed by any non-digit". Chances are your JSON data begins >> with a non-digit, so you'd just have to insert a space in the event >> that you're JSON-encoding a flat integer. (Which might not ever >> happen, if you know that your data will always be an object.) >> >> ChrisA > > So on the first recv() call, I set the buffer at 1 character and I iterate over single character until a non-digit character > is encountered? More efficient would be to guess that it'll be, say, 10 bytes, and then retain any excess for your JSON read loop. But you'd need to sort that out between the halves of your code. ChrisA