sockets - recv buffer not matching return bytes -
Is it possible to not match the number of bytes given by the call to the buffer of the recall socket call? For example:
const int len = 1024; Four buff [lane]; Int bytes = Rick (socket, buff, lane, 0);
It should not always be true: strlen (buf) = bytes
?
edit1:
I should note that I know that the return of rec buffer can return less than the size. I am trying to measure the amount of bytes in the buffer after the rec call. This is not a binary message, thanks.
Stellen
is only counted first (and not included in this) < Code> '\ 0' . The data returned by recv
can contain many '\ 0'
characters - or none. So in general, this will not be true - and if it ever happens, then it will happen by chance.
Appendix:
Even with the guarantee "non-binary" message, recv
and Stellen is still counting different things, say that you can see the string "phobor" - -
recv
characters by reading the letters 'F' o '' o 'B Return to 'A' 'R' '\ 0'
buffer and return to 7 and return the result by calling strlen
on the result.
Note that in this situation, because recv
can return a short value result is also not guaranteed to be a valid string - say recv
So you decide to give only 3 characters: then it will be 'f' o 'o' / code> buffer and return 3. Calling on this
strlen
will give an uncertain result, because recv
did not write a string terminator.
Comments
Post a Comment