MasterDucky
November 8th, 2009, 08:18 AM
I dont really understand why we should add +1 to the buffer length in send().
If you send for example "hello" which is 5 bytes + 1 for the '\0'.
It will send "hello" + 1 byte which will be a garbage char because send() doesnt put '\0' at the end either.
send(mySocket, "hello", 6, 0);
So on the other side you will get (after making sure you got it all) "hello" + 1 garbage char.
So now if you do
buffer[i] = '\0';
you will put your '\0' after the garbage char because you have recieved 6 bytes.
So wouldnt it be better to send only strlen(buffer) without the +1 ?
If you send for example "hello" which is 5 bytes + 1 for the '\0'.
It will send "hello" + 1 byte which will be a garbage char because send() doesnt put '\0' at the end either.
send(mySocket, "hello", 6, 0);
So on the other side you will get (after making sure you got it all) "hello" + 1 garbage char.
So now if you do
buffer[i] = '\0';
you will put your '\0' after the garbage char because you have recieved 6 bytes.
So wouldnt it be better to send only strlen(buffer) without the +1 ?