Socket Performance

Bryan Olson fakeaddress at nowhere.org
Fri Mar 14 03:42:05 EDT 2008


castironpi at gmail.com wrote:
[Dennis Lee Bieber had written:]
>>         Or create a protocol where the first 16 bits (in network byte order)
>> contain a length value for the subsequent data, and use a receive
>> process that consists of:
>>
>> leng = ntoh(socket.recv(2))
>> data = socket.receive(leng)
>>
>> (the send can combine the length with the data into a single packet)
> 
> Are two 'sends' guaranteed to arrive as at least two 'receives'?

No. Nor are they guaranteed to arrive as at least most two.

> Send-3:  xxx
> Send-3:  yyy
> Receive-6:  xxxyyy

Can happen, though I think the problem with Dennis's code is the
other way. The recv in

    leng = ntoh(socket.recv(2))

might return one byte of data, not two. The latter recv is similar.


-- 
--Bryan



More information about the Python-list mailing list