In C (UNIX), how can I transfer and receive a file in multiple blocks using a socket?
For example, if I had a file of 1234 bytes, and a block size of 500, I would transfer:
- 500 bytes,
- then 500 bytes,
- then 234 bytes
I have attempted this using fseek, read, write, but I just cannot get the logic right. Even a good reference would be much appreciated.
My socket routines are:
int readn(sd, chunk, bytesToRead);
int writen(sd, chunk, bytesToWrite);