I have write a TCP client and server in C. These software run on the same computer ONLY.
1) My TCP client send a command to the server (localhost).
2) The server works hard and give a response.
The problem is if the TCP Client closes the connection, I am unable to detect a client connection closed WHILE server is going to do its long work. I can only detect this with the SEND function, but it’s too late because the server have already work.
I understand that this must be very hard to make this detection if the machines are remote. In my case, it is the same machine, which should make the task easier, but I have not found a solution … Can be with the select function?
Thanks you.
You can do it with
selectlike this:selectfor read events on the socket. Soselectunblocks when the socket is readableselectwill unblock andrecvwill read 0 bytes. If so, you can stop the worker thread