I am writing a network C program where a client sends a block of data to a server, and I want
to make sure that all data have been read by the server before I close the socket from the client side. I thought of sending a special ‘ok’ character back from the server to the client, but I am thinking that if something wrong happens during the execution of the server
program and the server closes the pipe from his side (e.g. read system call fails), the client is going to wait on a read system call for something that will never come. Any idea about how I can solve this?
thanks,
Nikos
If you are using TCP consider this: once you send the data, even if you close the socket / exit the program, the TCP stack will continue to do its best to send it.
Once you
send/writethe data, it’s gone from your hands. It’s copied in a kernel buffer and sent some time later. Behind the scenes (somewhere deep innetinet) the connection is not closeduntil all sent data has been acknowledged / the connection is terminated due to other reasons.