Re: Socket differences between localhost and LAN (or Internet)
"Wyvern" <davinator17@hotmail.com> wrote in message
news:1157959788.824391.237830@p79g2000cwp.googlegroups.com...
Also using William's idea is not so great for me since I have to
rewrite lot of parts in my program and it would be deadly for it.
Well, sadly, that's what you will have to do.
You must understand that TCP (unlike UDP where there are fewer guarantees)
works in a stream-oriented rather than message-oriented way. If the sender
sends 10,000 bytes, the only guarantee is that 10,000 will be received or an
error will be signalled. It would be permissible (though not likely) that
the receiver would get 1 byte in each of 10,000 calls to recv().
William, excuse me, but when u "keep calling recv() until all data is
received", what about the send procedure ? How u tell the server that
you got all the data ? You cannot rely on the received buffer data 's
length, so you cannot really know what is sent or correctly received...
That's why messages sent over TCP often have fixed length headers or headers
that end with a special delimiter.
With HTTP for example, the header of a request is that portion of a message
from the first byte up to the double end-of-line indicator. The receiving
server keeps receiving until it sees the two EOLs. Then it looks into the
header for the keyword "Content-Length:" (I might have spelled that
incorrectly). Once it does that it knows how much data the client has to
send. Finally it keeps calling recv() until it has gotten all of the bytes
indicated by the length header.
Regards,
Will