I am using a client socket to make a HTTP call to retrieve an image. Even though the recv
call receives 36791 bytes, the buffer only has 4 bytes in the response body (the BUFF_SIZE
has been set to 50000 for testing purposes). I have tried to make subsequent calls to recv but 0 bytes are returned from the subsequent calls. Would appreciate any help to understand why the buffer does not contain the full response from the socket recv
as expected.
Asked
Active
Viewed 95 times
-1

Roy Chan
- 287
- 3
- 10
-
2Please don't include text as image - but use properly formatted text instead. Also, please post enough code and other detail so that we can actually understand and ideally reproduce a) what you are doing (code) b) what you expect to happen c) what happens instead. See also [How to create a Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example). – Steffen Ullrich Nov 05 '22 at 18:12
-
2You receive jpeg image data, not a string. `char *` strings are expected to be null-terminated and binary data is likely to conatin zero bytes that would be treated as end of string. So, you need to find/implement parsing function that would `char *` data and data length as a separate parameter. – dewaffled Nov 05 '22 at 18:14
-
And you indeed should never expect to receive all data with single read when reading TCP sockets. – dewaffled Nov 05 '22 at 18:17
-
thanks @dewaffled , that makes sense will try to fix that. I understand that single read is not the right implementation, was just wondering about the buffer and wanted to fix that first. – Roy Chan Nov 05 '22 at 18:18
-
Expanding on Steffen's comment, see "[Why should I not upload images of code/data/errors when asking a question?](//meta.stackoverflow.com/q/285551/90527)" – outis Nov 06 '22 at 04:21
-
Does this answer your question? [Should recv() result must be equal to buffer length?](/q/17224500/90527) – outis Nov 06 '22 at 04:41