beanscake has asked for the wisdom of the Perl Monks concerning the following question:
please what is better way to determine if a socket is still active or closed here is what i have been able to come up with
use warnings; use strict; use IO::Socket::INET; my $sock; sub Connect_Server { $sock = IO::Socket::INET->new( PeerAddr => '127.0.0.1', PeerPort => 80, Proto => 'tcp', Timeout => 8 ) or die("Connect failed: $@\n"); } sub AmStillConnected { return unless defined $sock; return unless $sock->connected(); return 1; } sub test_status { if (&AmStillConnected()){ print "am connected\n"; }elsif(!&AmStillConnected()){ print "not connected\n"; } } &Connect_Server(); &test_status();
|
|---|