Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: Python recv loop

Reply
Thread Tools

Re: Python recv loop

 
 
Dave Angel
Guest
Posts: n/a
 
      02-11-2013
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Triple nested loop python (While loop insde of for loop inside ofwhile loop) Isaac Won Python 9 03-04-2013 10:08 AM
Python recv loop Ihsan Junaidi Ibrahim Python 7 02-12-2013 03:09 AM
Re: Python recv loop MRAB Python 0 02-11-2013 01:55 AM
Re: Python recv loop Dave Angel Python 0 02-11-2013 01:22 AM
How to empty the recv buffer without recv() ? deepak nayak C++ 3 10-25-2007 08:14 AM



Advertisments