![]() |
Re: Python recv loop
On 02/11/2013 10:02 AM, Ihsan Junaidi Ibrahim wrote:
> > <snip> > > print 'message length is {0}'.format(nbuf) > > while True: > buf = sock.recv(nbuf) > > if not buf: > break This loop doesn't terminate till buf is zero length, which it will be eventually. At that point, you've overwritten the real data you may have gotten. So the loop is just plain wrong. Uwe MRAB's code, since there's no promise that all the data will be returned in a single call. Keep accumulating it as you loop. > > slen = len(buf) > str = "{0} bytes received: {1}".format(slen, buf) > print str > return 0 -- DaveA |
| All times are GMT. The time now is 10:43 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.