Sockets: Sending/receiving arbitrary amounts of data

Grant Edwards grante at visi.com
Wed May 2 12:20:26 EDT 2001


In article <iNXG6.36968$qc2.10727931 at typhoon.southeast.rr.com>, Steve  Holden wrote:
>"Daniel Klein" <danielk at aracnet.com> wrote in message
>news:pneoetskbee729lra63ksqj5o06vkpeo84 at 4ax.com...

>> Just starting to get my head around sockets and I'm using PP2E
>> by Mark Lutz as my guide.
>>
>> The examples all seem to indicate that you need to send/recv a
>> specific (maximum) amount of data. The examples all use '1024'
>> bytes to send or recv. Although this can be increased, there is
>> always the possiblility of needing more.
>
>Indeed. A big problem in networking generally is knowing what to expect!
>
>> What if the server doesn't know in advance how much data will
>> be sent from the client? The server is waiting for '1024' bytes
>> and the client sends down 10k.
>
>The server's recv() call will return 1024 bytes, and the
>remainder will be buffered somewhere in the socket between the
>client's (sender's) transport layer and the receiver's
>(server's) transport layer.

That is true for TCP.  Is it true for UDP? If you're using UDP
a recv() on a UDP socket would discard extra bytes if the size
of the buffer is smaller than the UDP segment.  Hmm, can you call
recv() on a UDP socket, or do you have to use recvfrom()?

-- 
Grant Edwards                   grante             Yow!  Fold, fold,
                                  at               FOLD!! FOLDING many items!!
                               visi.com            



More information about the Python-list mailing list