Read exactly five bytes for the TLS record header, unpack the content type, version, and length, then keep receiving until you’ve collected the promised payload length.
The solution reads the fixed five-byte TLS header first, then reads exactly the payload length promised by that header. That pattern matters because TCP gives you a stream of bytes, not tidy message-sized chunks.
Here’s what’s happening: the header tells us how much more to read. If we pretend one recv() always returns the whole payload, the code may work in a toy case and then betray us in real protocol work.