The Plack suite commonly uses the http://0:port
. E.g. the following
plackup -MPlack::App::Directory -e 'Plack::App::Directory->new(root=>".");'
prints
HTTP::Server::PSGI: Accepting connections at http://0:5000/
However, the LWP::UserAgent
(or some deeper called modules) didn't accepts it, e.g. the:
perl -MLWP::UserAgent -E '$u=LWP::UserAgent->new;$res=$u->get("http://0:5000/valid/path");print $res->status_line'
prints:
500 No Host option provided
but the
perl -MLWP::UserAgent -E '$u=LWP::UserAgent->new;$res=$u->get("http://localhost:5000/valid/path");print $res->status_line'
prints
200 OK
The question is: who is wrong?
http://0:port
valid, e.g. the LWP is "wrong"A port number is a 16-bit unsigned integer, thus ranging from 0 to 65535. For TCP, port number 0 is reserved and cannot be used, while for UDP, the source port is optional and a value of zero means no port.
Port 0 is a wildcard port that tells the system to find a suitable port number. Unlike most port numbers, port 0 is a reserved port in TCP/IP networking, meaning that it should not be used in TCP or UDP messages. Network ports in TCP and UDP range from number zero up to 65535.
As best practice, Port 0 should not be seen or used on your network, although this port is a valid TCP/UDP port, it is highly recommend that one should block any traffic using this port at your firewall.
When trying to bind on port 0, actually a random port is selected.
The output of the Plack suite is the output of a server. A server typically bind
s a socket to a certain port and address in order to serve content there.
The notation http://0:port
means in this case: listen on port port
on all addresses of this machine. This is handy if you don't know or don't want to specify all addresses of the machine where the server should be reachable.
The output of the LWP::UserAgent ist the output of a client. In order to open a connection to a server, you must explicitly specify the address and the port to connect to. 0
is no valid IP address, therefore the connection fails when you connect to http://0:port
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With