Net::EmptyPort(3pm) | User Contributed Perl Documentation | Net::EmptyPort(3pm) |
Net::EmptyPort - find a free TCP/UDP port
use Net::EmptyPort qw(empty_port check_port); # get a socket listening on a random free port my $socket = listen_socket(); # 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"; }
Net::EmptyPort helps finding an empty TCP/UDP port.
my $socket = listen_socket();
Returns a socket listening on a free port.
The function recognizes the following keys in the hashref argument.
my $port = empty_port();
Returns a port number that is NOT in use.
The function recognizes the following keys when given a hashref as the argument.
See <http://www.iana.org/assignments/port-numbers>
To maintain backwards compatibility, the function accepts scalar arguments as well. For example, you can also find an empty UDP port by specifying the protocol as the second parameter:
my $port = empty_port(1024, 'udp'); # use 49152..65535 range my $port = empty_port(undef, 'udp');
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.
The function recognizes the following keys when given a hashref as the argument.
To maintain backwards compatibility, the function accepts scalar arguments as well in the form described above.
The function recognizes the following keys when given a hashref as the argument.
To maintain backwards compatibility, the function accepts scalar arguments as well in the form described above.
Incompatible changes: Before 2.0, "wait_port($port:Int[, $sleep:Number, $retry:Int, $proto:String])" is a signature.
Tokuhiro Matsuno <tokuhirom@gmail.com>
kazuhooku
dragon3
charsbar
Tatsuhiko Miyagawa
lestrrat
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
2017-06-23 | perl v5.24.1 |