freddo411 has asked for the wisdom of the Perl Monks concerning the following question:
the following subroutine seems to cause this message (on Windows) "Terminating on signal SIGALRM(14)" when the calling code exits.
How can I fix this...sub portAlive { my $proto = getprotobyname('tcp'); my $iaddr = inet_aton($host); my $paddr = sockaddr_in($port, $iaddr); socket(SOCKET, PF_INET, SOCK_STREAM, $proto) || warn "socket: $!"; eval { local $SIG{ALRM} = sub { die "timeout" }; alarm($timeout); connect(SOCKET, $paddr) || error(); alarm(0); }; if ($@) { close SOCKET || warn "close: $!"; # print "$hostname is NOT listening on tcp port $portnumber.\n"; return 0; } else { close SOCKET || warn "close: $!"; # print "$hostname is listening on tcp port $portnumber.\n"; return 1; } }
OR
How can I detect if a port is in use?
-------------------------------------
Nothing is too wonderful to be true
-- Michael Faraday
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Detecting a port "in use" on localhost:$port
by ig (Vicar) on Apr 21, 2009 at 23:34 UTC | |
by freddo411 (Chaplain) on Apr 22, 2009 at 01:51 UTC | |
|
Re: Detecting a port "in use" on localhost:$port
by almut (Canon) on Apr 22, 2009 at 05:22 UTC | |
by freddo411 (Chaplain) on Apr 22, 2009 at 18:18 UTC | |
|
Re: Detecting a port "in use" on localhost:$port
by ikegami (Patriarch) on Apr 21, 2009 at 22:24 UTC | |
by freddo411 (Chaplain) on Apr 21, 2009 at 22:35 UTC | |
by ikegami (Patriarch) on Apr 22, 2009 at 01:11 UTC |