Re: Socket differences between localhost and LAN (or Internet)
Wyvern wrote:
Wait wait wait Will,
I need to focus on two things:
Recv() is not reliable , ok, is the Send() reliable too ?
And then, let's assume that I have received some data with Recv(), but
I see that the total amount of received bytes is not what I expected,
what I have to do ? Clear the buffer and ask a retransmission to the
server UNTIL I got the exact amount of bytes ?
You have confused "reliable" with "meets your expectations." The
network does not preserve the count of bytes sent in one send() call. It
sends a stream, not a fixed size. If you do not receive the number of
bytes you need, you may call recv() again. No request for
retransmission is needed. No vast changes to your program are needed.
Just write the receive function to get what you need.
Because what i do not understand now is this :
When you launch the command:
...
bytes_recv=Recv();
...
bytes_recv cannot be the exact number of bytes that have been really
sent, but what happens ? The Recv() has returned a number, and the
program proceeds on its way, why is Recv() so stupid to return a value
even if it is not the complete amount of bytes received ?
Because routers are free to break up messages into any sizes they like.
This makes the internet possible.
When I decided to use blocking functions, I expected to have a Recv()
that didn't proceed untill ALL data was sent, but now it seems that I
have to use it many times, until I get the data...
Now I am confused, what should I do ?
Fix your code.
Ex1:
while(brecv<1024)
{
brecv=recv(); //Keep receiving, no request for retransmission
}
That is buggy. Save the data you get. Get more. Append it to what you
saved. This would require something like
totalrecv = 0;
while (totalrecv < 1024)
{ brecv=recv(buf+totalrecv, 1024 - totalrecv);
totalrecv += brecv;
}
--
Scott McPhillips [VC++ MVP]