On Tue, Feb 12, 2013 at 12:41 PM, Ihsan Junaidi Ibrahim <ih...@grep.my> wrote: > > On Feb 11, 2013, at 11:24 PM, Chris Angelico <ros...@gmail.com> wrote: > >> On Tue, Feb 12, 2013 at 2:11 AM, MRAB <pyt...@mrabarnett.plus.com> 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 -- http://mail.python.org/mailman/listinfo/python-list