If it's a TCP socket, it has internal means to validate that the connection is still active. If the connection goes down, you typically get an error from any function you call tell you so (send, recv, etc).

If you're using UDP you will need to write the keepalive logic yourself.