Your code is already breaking up the file into chunks. By calling <FILE>
each chunk will be one line. But there are several problems:
- If the line gets too long and will not fit into a packet it cannot be transferred
- UDP does not guarantee the delivery, so you receiver might miss data or might even duplicate data
- UDP does not guarantee the order of delivery, so your receiver might get later data first
These drawbacks are probably not acceptable with file transfer, so you need to add layers on top of UDP to work around them, e.g. sequence numbers to detect duplicates and reordering and acknowledgments to trigger resubmissions on lost data. Or you could simply use TCP instead which has all these and more built in already.