Socket Receive Buffer
John Burton
john.burton at jbmail.com
Mon Mar 8 03:51:38 EST 2004
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.
More information about the Python-list
mailing list