Just add the message length to the beginning of your message as an integer value (don't forget to convert it via
htonl()
[
^]. You could also send this value independently of your actual text and let the receiver re-assemble it when handling the input messages.