Generally there is no way to do this with SOCK_STREAM
socket types such as TCP. SOCK_DATAGRAM
(for IP, this means UDP) and SOCK_SEQPACKET
(for IP, there is no such thing) would do what you want, but with different limitations of their own.
In any case, the solution is that you need to do your own data buffering and framing. That is, you need to include in-band information in the stream you send that allows the recipient to reconstruct the "packet" boundaries you intended.