Quote:
Originally Posted by
Kovalevski
It is a very good point the MTU length, first of all thank you for this info because I didn't know , but when I tested the program, many messages arrived to the server
How large are your messages?
TCP is not received in dependably-sized chunks, it is a
stream. If they sent 30 bytes and you only read 2, that's okay, just read 28 more. Conversely, if they sent 5000 bytes and you got 1000, just keep reading, you'll get the rest eventually.
If the lengths are variable, you should encode them as part of the stream. Otherwise you won't know how much to expect and, as you've discovered, getting the "right" size from recv() is not dependable, mostly because there is no such thing.
I'm guessing you overloaded it until it was unable to cope. It started delivering data immediately instead of bundling multiple packets together politely.
Or, the server might even have been running out of memory. No kind of connection can cope with that. Each TCP connection takes a good chunk of it.