Re: Python recv loop

Discussion in 'Python' started by Dave Angel, Feb 11, 2013.

  1. Dave Angel

    Dave Angel Guest

    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
    Dave Angel, Feb 11, 2013
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. deepak nayak
    Replies:
    3
    Views:
    411
    =?UTF-8?B?RXJpayBXaWtzdHLDtm0=?=
    Oct 25, 2007
  2. Ihsan Junaidi Ibrahim

    Python recv loop

    Ihsan Junaidi Ibrahim, Feb 11, 2013, in forum: Python
    Replies:
    7
    Views:
    153
  3. Dave Angel

    Re: Python recv loop

    Dave Angel, Feb 11, 2013, in forum: Python
    Replies:
    0
    Views:
    107
    Dave Angel
    Feb 11, 2013
  4. MRAB

    Re: Python recv loop

    MRAB, Feb 11, 2013, in forum: Python
    Replies:
    0
    Views:
    105
  5. Isaac Won
    Replies:
    9
    Views:
    349
    Ulrich Eckhardt
    Mar 4, 2013
Loading...

Share This Page