Socket Receive Buffer
Bob Ippolito
bob at redivi.com
Mon Mar 8 10:58:17 EST 2004
On 2004-03-08 03:51:38 -0500, John Burton <john.burton at jbmail.com> said:
> christofer wrote:
>
>> I am writing a small IRC type server. I also have a small test client
>> for obvious reasons. My problem is that when receiving input from the
>> server, my client sometimes ends up with two messages in the same
>> input buffer, which obviously causes problems. Anybody know why it is
>> doing this?
>
> It's the way that sockets work.
> They are just a stream of bytes.
> You *might* read the whole message you sent in one go, or you might get
> 60% of the message in one read and 40% in the next, or you might be two
> messages together, or any other cominbation.
>
> Often you'll get each message seperately when testing on a low load
> local network but get different results over the internet.
>
> You need to find the end of the messages yourself, and remember that a
> single read might not return the whole of the messasge.
>
> Yes it's a pain but that's how it works.
And this is exactly why you can and should use a higher level
abstraction, like Twisted or at least medusa/asyncore.
-bob
More information about the Python-list
mailing list