Hello all.
When you receive data from a socket, you pass a buffer into the "recv()" with the maximum number of bytes you wish to receive per that call.
Now imagine the following sizes:
Packet = 28 Bytes
Buffer = 56 Bytes (28*2)
You call "recv()" with buffer and it's size 56.
You get 43 Bytes from "recv()".
You process the first 28 Bytes (packet).
Now there is 15 (43-28) Bytes left on the buffer of another packet, which leaves you with 2 options:
1) Tell "recv()" to fill Buffer+43 (where part of second packet data ended) with 56-43 (remaining buffer) Bytes, after processing the second complete packet you can start all over from beginning by passing the start of buffer with maximum length, Sounds useless... If we make the buffer longer, say 56 Bytes more, it'll take longer to reach the end of the buffer, thus simply receiving and processing until the time comes, but when it comes you can only fill up the limited remainder of the buffer and start over.
2) You can process 28 Bytes (packet) and move everything after to the start of buffer.
In here: http://beej.us/guide/bgnet/output/html/singlepage/bgnet.html#sonofdataencap . It is mentioned that you can get around the moving by using a "circular buffer". As I understood it it would be the "1)" case where you will stumble onto that problem of "limited remainder of buffer".
I think I misunderstand something here. What is the way to go about it? Please assist