kardster has asked for the wisdom of the Perl Monks concerning the following question:

I have a client/server using sockets with the following scenario:
server opens a listen socket client opens the socket server accepts server forks child: loop server sends data to new socket while socket is active
The problem I have is that the server never reads the client so I don't know if the socket is dead. Any pointers on how to determine whether my socket is dead or not?

I'm using ActivePerl on Windows NT. I am using Socket, not IO::Socket.

Replies are listed 'Best First'.
Re: Determining socket status
by merlyn (Sage) on Mar 09, 2001 at 22:35 UTC
    If the socket is dead, then I/O will fail. Check the response from your I/O. (Yes, this is one of the few times when "print blah blah or whatever" actually makes sense.)

    If you want to poll without I/O, then consider a simple query, like getpeeraddr(), which will fail if the socket isn't alive.

    -- Randal L. Schwartz, Perl hacker

Re: Determining socket status
by mikfire (Deacon) on Mar 10, 2001 at 00:08 UTC
    While merlyn's advice will likely be more sage than mine, this is one of the few times where I have found eof() to useful in a perl program.

    mikfire