Everyone who sends more than a handful of bytes over sockets has to somehow make the receiver know how many bytes belong to one packet and make the receiver reassemble incoming data until the eventual data packet is complete.
I have to do this too and I wonder if there is some helpful code for Linux C to accomplish this.
Actually to me one of the greatest mysteries of sockets is the question why there is no native support to this. Perhaps there is and I simply missed it?
I don't need an extremely oversized framework that allows all kind of complex configuration (and requires hours of understanding). Just an aid that does the accumulation of data packets and invoke a callback function when one packet is completed.
To make it a bit more clear. What I am about to implement on my own would be something like
- a function that gets data, data size and an open socket. It adds size to the data and sends data over the socket.
- a function that I forward received data to, plus the socket data came from plus a callback function. The function assembles data depending on the socket. When the packet is complete, the callback is invoked so the callback gets exactly the data packet that was sent.
Having something like this already implemented would be very helpful and probably less error-prone than what I would do.