Hi,
I am writing client/server program using sockets in c. I need to solve following problem: client should detect disconnection with server and when it happens, try to connect another one. I have been looking for materials how socket disconnection works and I found out that there is not direct way to detect it. I know that if one side tries to make write on closed socket file descriptor, it will get SIGPIPE and if it tries to read data from it, read will return 0. The only solution I have found is that I will have background thread in client program which will connect server (who will accept this connection and also run thread for handling requests) and try to get data from server in busy waiting, as long as it read more than 0 byte, I know that connection is OK. If it reads 0 byte, than I will know that something bad happened and need to connect another server. Is there other better solutions for solving this problem? Or what kind of solution is mine?