in reply to Detecting disconnection from client using IO::Socket Objects.

Without really knowing how you have implemented your server, I can give you the following advice if you are doing non-blocking I/O with the help of IO::Select or IO::Poll:

After getting a read-event on the socket, you'll go to do your sysread, and you'll get back 0 bytes. That means the client closed the socket. The following code snippet illustrates:

my $bytes_read = $socket->sysread($buf, $max_read_len); if (not defined $bytes_read) { print "ack! error on the socket\n"; } elsif ($bytes_read == 0) { print "the socket was closed\n"; } else { print "woo hoo! I read $bytes_read bytes from the socket...\n"; }

You might want to look at this node for more info:
Detecting a closed socket

HTH

--
3dan

Replies are listed 'Best First'.
Re: Re: Detecting disconnection from client using IO::Socket Objects.
by Abroxa (Initiate) on Sep 17, 2003 at 17:08 UTC
    At first many thanks to sgifford and 3dan

    And yes, I do use IO::Select with Nonblocking Handles and am waiting for can_read() has something for me.
    Do I see that right that in my - lets call it "check_connected" - routine, I have to call sysread on the socket, and my connection status depends on its ( sysread's ) return values? Seems to make sense to me.

    -trial 'n error with many thanks :)-
    Abroxa