@monersss At the moment, with my example, that happens when you get a timeout. But again, that would require some "out-of-band" signaling, meaning: in addition to the "payload", the jpg file, some control information must be exchanged. And that is part of a protocol. That could be pretty simple. If I grab one out of the air, it could be:
Define record types, where the first letter defines the type of the record, followed by 3 bytes record length, followed by the payload, like:
'fnnn': filename (of length nnn)
'd128': data
'x000': done
You would first receive 4 bytes, decode type and length, and then receive further 'length' bytes. And for every record received, your LoPy would send a confirmation, like the three bytes: "ok!" or "bad", in case of errors (or just a single byte).
That would implement flow control and the EOF signal. It does not have other elements like check sums and sequence control. But you might not need that.