There are really two approaches to take here:
1: Terminate every message with a special character, like a newline. Read the buffer until you reach this character; parse the results, and then continue until the buffer is empty or until it doesn't end with the special character.
2: Make the first two/four bytes of every message the message length. Read that many bytes from the buffer, parse the message, and then repeat until there are less than that number of bytes in the buffer, or the buffer is empty.