How to check TCP server status

Please tell me according to C/C++ socket programming; how client can check whether server is running or not during TCP communication.

If the socket connection fails, either there was a network failure or the server failed to run. Use errno to determine which.