Let the client confirm reception of data through the protocol that you use.
E.g.
client requests file
server sends first 1000 bytes
server waits for acknowlege
server sends second 1000 bytes
server waits for acknowlege
etc etc
Further, when a client disconnects nicely, the socket at the server side will indicate that there is data received but reading it will return 0 bytes. You might also get some sigpipe errors that you have to catch (not 100% sure, but probably when you try to write over a closed socket).
FYI, there is a
dedicated programming forum