If the server closes the connection you should recieve an EOF on the socket. HOWEVER, tcp is designed to run over very slow and lossy networks, it is hard to tell the difference between a very slow/lossy network and a dead server.. In fact in tcp terms it is impossible. TCP works on a series of timeouts EVENTUALLY it will work out that the server is dead but it will take a long time.
Having said all that things to consider.
- Write a ping method into your server, get it to send a datagram every n seconds. If the client does not recieve that datagram then you know the server is dead.
- Look at the socket option SO_KEEPALIVE this will implement a ping protocol for you, however its timeouts are huge. 2 Hours or more, you can change this time out on a persystem basis (exactly how depends upon the system), you cannot do this AFAIK on a per connection basis.
For more information on this topic have a look at the UNIX Socket FAQ
This document is as relivent to perl as it is to C, dont be put off by the fact that the examples are all in C. TCP is TCP is TCP.