in reply to How to find out whether socket is still connected?
eof might work. Whether your socket is non-blocking and whether select works on your system is likely to be important.
After Compline,Zaxo