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

ive wanted to post a new question because my problem seems to be not related to my original post thread. ive added an eval/die command to an IO::Socket call in hope to terminate a HANG-ing socket call process. but everything seems to fail? the eval/die command doesnt seem to work. heres my code:
use IO::Socket; sub doit { $ip1="210.22.106.31"; $host="$ip1"; $port="23"; $fnd=""; $pong=`ping -c 3 $host`; $fnd=($pong=~m/(..)%/gi); $xcd=$1; if ($xcd!=00) { $SIG{ALRM} = \&timed_out; eval { alarm (3); $remote = IO::Socket::INET -> new ( Proto => "tcp", PeerAddr => $host, PeerPort => $port, Timeout => 2 ) or die "." ; alarm (0); }; sub timed_out { die "."; } $| = 1; if ($remote) { close $remote; print "Socket ready...\n"; } else { print "Try again...\n"; } } else { print "Pinged timed out!\n"; }
Is there any workaround for this? I just want to eliminate the HANG thing. Lovelots, Cherry.

Replies are listed 'Best First'.
Re: is there an eval/die for sockets?
by tadman (Prior) on Jun 07, 2002 at 23:08 UTC
    One way to do it is to use non-blocking sockets and check up on them until they connect or you grow too impatient. You could do this with an IO::Socket modification Non-blocking TCP connections or your own equivalent solution.