One way to do is adding a delimiter character at the end of each message and deal with this delimiter in your inputStream.read()
loop.
You can also specify the length of the message and appending the length at the beginning of the message. Usually we decide a message format and we stick with it.
i.e. Message format:
=========================================================
= Length (2 bytes) | Message =
=========================================================
You might want to have a look at this link