NAME
Net::EmptyPort - find a free TCP port
SYNOPSIS
use Net::EmptyPort qw(empty_port check_port);
# get a random free port
my $port = empty_port();
# check if a port is already used
if (check_port(5000)) {
say "Port 5000 already in use";
}
DESCRIPTION
Net::EmptyPort helps finding an empty TCP port.
METHODS
- empty_port
-
my $port = empty_port();
Get the available port number, you can use.
Normally, empty_port() finds empty port number from 49152..65535. See http://www.iana.org/assignments/port-numbers
But you want to use another range, use a following form:
# 5963..65535 my $port = empty_port(5963);
- check_port
-
my $true_or_false = check_port(5000);
Checks if the given port is already in use. Returns true if it is in use (i.e. if the port is NOT free). Returns false if the port is free.
- wait_port($port:Int[, $sleep:Number, $retry:Int])
-
Waits for a particular port is available for connect.
This method waits the
$port
number is ready to accept a request.$port
is a port number to check.Sleep
$sleep
seconds after check the port. You can specify$sleep
in floating number.And, retry
$retry
times.Return value : Return true if the port is available, false otherwise.
AUTHOR
Tokuhiro Matsuno <tokuhirom@gmail.com>
THANKS TO
kazuhooku
dragon3
charsbar
Tatsuhiko Miyagawa
lestrrat
SEE ALSO
LICENSE
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.