"Ron Natalie" <ro*@spamcop.netwrote in message
news:45**********************@news.newshosting.com ...
>
>>
This is acutally off topic, as this is a TCP/IP problem, not a C or C++
problem. However, the problem is not with your program, but in a MTU
(Maximum Transmission Unit) somewhere between the sending and receiving
computers.
Actually, it might not even be a MTU issue. TCP/IP doesn't deal
with packets on the application side. It's a byte stream. The
size you get from a read has nothing to do with what is written
on the other side (other than that you can't obviously read more
than what was sent).
A new user to TCP/IP usually does something like the file:
open the connection to the server
recieve data
Process the bytes reeived.
go back to receiving data.
That's where the problem comes in. For small packets this will work, but
even if they are small sometimes they get broken anyway. So you can't
process the data received until you piece it back together. So you have to
do more like the following.
open the connection to the server
receive data
add the data to the buffer
Is the data complete? If so process it and clear the buffer
go back to receive data
For a simple file transmission it is fairly simple, just keep adding the
data to the buffer until the socket closes. Then you have all the data.
But in a client/server or peer to peer application data is usually sent back
and forth and are usually messages. There are different schemes for keying
the end of the data. For ASCII data a simple null terminator is sufficient.
For binary data, you normally send the length of the data. That way the
application knows when the data is complete.
Yes, it's a byte stream, and needs to be treated as such. But the new user
to TCP/IP usually doesn't, they treat a packet as complete data, which it
sometimes isn't.