I have a socket which receives information in packets of 1024 characters or less. In those packets I some messages or parts thereof. Each message is ended with 2 characters.
The problem appears when there is fragmentation of messages across two packages. What algorithm do you recommend to handle this fragmentation? (I’m not looking to reinvent the wheel here, because I think this is a ubiquitous problem).
Example:
|011 012 013 014 \r\r 021 022 023 | 024 \r\r 031 032 033 | 034 \r\r 041 042 043 044 \r\r |
| … | -> packet
xxx xxx … \r\r -> a message
1 Answer