The receiver has to know the exact number of bytes. How that is achieved depends on which protocol is used to transmit the data from the sender to the receiver. In the case of HTTP, it could be deduced from the Content-Length: header. If you send only one message from sender to receiver, the receiver could count the number of bytes until EOF. Or you transmit the number of bytes together with the actual data.
But the receiver can not determine the correct length from the pure bytes alone.