1 of 2 people found this helpful
Easiest way would be to put a header on your data. For example, if your data is 30 bytes long, you could first send the bytes 0xAB 0x1E where 0xAB is a sync byte and 0x1E is the payload length.
Start up a thread that keeps reading single bytes of data, throwing them away until the sync byte is received. Once the sync byte is received, read one more byte to get the payload length. Then read [payload length] bytes and you should have your data.
There are, of course, ways to make this more robust (checksums), but this should work for you.
EDIT: edited reply with more detailed approach
Thank you for your response!!!