TCP is a stream protocol, there are no boundaries. If there are 30 bytes available to be received, and you're waiting for a string, you can't be sure that these 30 bytes are your string: it could be a part of it, or it plus the beginning of the next data. So you have to handle the string end explicitely, either by sending the size first, or by sending the terminating '\0'.