# instead of simply reading on the socket filehandle, we'll # use IO::Select here to give us timeout capabilities. # add the socket to our IO::Select object. # my $sel = new IO::Select ($sock); # $sock is a IO::Socket obj # now wait until our IO::Select obj tells us that one of its # sockets (and we only added one) is ready to be read (or # times out). # if (my @socks = $sel->can_read($timeout)) { $sock = shift(@socks); # ...read socket data, or print warning if the # socket was closed remotely... } else { croak sprintf("Timed out, socket connection status: %d\n", defined($sock->connected())); }