Net-Server

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

        me as in the following:

            perl -e 'use base qw(Net::Server); main->run(port => [20203,20203], host => "localhost", ipv => [4,6])'

            Binding to TCP port 20203 on host localhost with IPv4
            Binding to TCP port 20203 on host localhost with IPv6

        There is a special case of using host => "*" as well as ipv => "*".
        The Net::Server::Proto::_bindv6only method is used to check the
        system setting for "sysctl -n net.ipv6.bindv6only" (or
        net.inet6.ip6.v6only). If this setting is false, then an IPv6 socket
        will listen for the corresponding IPv4 address. For example the
        address [::] (IPv6 equivalent of INADDR_ANY) will also listen for
        0.0.0.0. The address ::FFFF:127.0.0.1 (IPv6) would also listen to
        127.0.0.1 (IPv4). In this case, only one socket will be created
        because it will handle both cases (an error is returned if an
        attempt is made to listen to both addresses when bindv6only is
        false).

        However, if net.ipv6.bindv6only (or equivalent) is true, then a
        hostname (such as *) resolving to both a IPv4 entry as well as an

README  view on Meta::CPAN

        following is output.

            perl -e 'use base qw(Net::Server); main->run(host => "*")'

            Resolved [*]:8080 to [0.0.0.0]:8080, IPv4
            Resolved [*]:8080 to [::]:8080, IPv6
            Binding to TCP port 8080 on host 0.0.0.0 with IPv4
            Binding to TCP port 8080 on host :: with IPv6

        BSD differs from linux and generally defaults to
        net.inet6.ip6.v6only=0. If it cannot be determined on your OS, it
        will default to false and the log message will change from "it will
        be handled" to "it should be handled" (if you have a non-resource
        intensive way to check on your platform, feel free to email me). Be
        sure to check the logs as you test your server to make sure you have
        bound the ports you desire. You can always pass in individual
        explicit IPv4 and IPv6 port specifications if you need. For example,
        if your system has both IPv4 and IPv6 interfaces but you'd only like
        to bind to IPv6 entries, then you should use a hostname of [::]
        instead of [*].

lib/Net/Server.pod  view on Meta::CPAN

me as in the following:

    perl -e 'use base qw(Net::Server); main->run(port => [20203,20203], host => "localhost", ipv => [4,6])'

    Binding to TCP port 20203 on host localhost with IPv4
    Binding to TCP port 20203 on host localhost with IPv6

There is a special case of using host => "*" as well as ipv => "*".
The Net::Server::Proto::_bindv6only method is used to check the system
setting for C<sysctl -n net.ipv6.bindv6only> (or
net.inet6.ip6.v6only).  If this setting is false, then an IPv6 socket
will listen for the corresponding IPv4 address.  For example the
address [::] (IPv6 equivalent of INADDR_ANY) will also listen for
0.0.0.0.  The address ::FFFF:127.0.0.1 (IPv6) would also listen to
127.0.0.1 (IPv4).  In this case, only one socket will be created
because it will handle both cases (an error is returned if an attempt
is made to listen to both addresses when bindv6only is false).

However, if net.ipv6.bindv6only (or equivalent) is true, then a
hostname (such as *) resolving to both a IPv4 entry as well as an IPv6
will result in both an IPv4 socket as well as an IPv6 socket.

lib/Net/Server.pod  view on Meta::CPAN

If I issue a C<sudo /sbin/sysctl -w net.ipv6.bindv6only=1>, the following is output.

    perl -e 'use base qw(Net::Server); main->run(host => "*")'

    Resolved [*]:8080 to [0.0.0.0]:8080, IPv4
    Resolved [*]:8080 to [::]:8080, IPv6
    Binding to TCP port 8080 on host 0.0.0.0 with IPv4
    Binding to TCP port 8080 on host :: with IPv6

BSD differs from linux and generally defaults to
net.inet6.ip6.v6only=0.  If it cannot be determined on your OS, it
will default to false and the log message will change from "it will be
handled" to "it should be handled" (if you have a non-resource
intensive way to check on your platform, feel free to email me).  Be
sure to check the logs as you test your server to make sure you have
bound the ports you desire.  You can always pass in individual
explicit IPv4 and IPv6 port specifications if you need.  For example,
if your system has both IPv4 and IPv6 interfaces but you'd only like
to bind to IPv6 entries, then you should use a hostname of [::]
instead of [*].

lib/Net/Server/Proto.pm  view on Meta::CPAN

        }
        push @info, [Socket::inet_ntoa($_), $port, 4] for @addr
    }

    return @info;
}

sub _bindv6only {
    my $class = shift;
    my $val = $class->_sysctl('net.ipv6.bindv6only'); # linux
    $val = $class->_sysctl('net.inet6.ip6.v6only') if ! length($val); # bsd
    return $val;
}

sub _sysctl {
    my ($class, $key) = @_;
    (my $file = "/proc/sys/$key") =~ y|.|/|;
    if (-e $file) {
        open my $fh, "<", $file or return '';
        my $val = <$fh> || return '';
        chomp $val;

lib/Net/Server/Proto.pm  view on Meta::CPAN

        proto => 'tcp',
    }

If a hashref does not include host, ipv, or proto - it will use the default
value supplied by the general configuration.

A socket protocol family PF_INET or PF_INET6 is derived from a specified
address family of the binding address. A PF_INET socket can only accept
IPv4 connections. A PF_INET6 socket accepts IPv6 connections, but may also
accept IPv4 connections, depending on OS and its settings. For example,
on FreeBSD systems setting a sysctl net.inet6.ip6.v6only to 0 will allow
IPv4 connections to a PF_INET6 socket.  By default on linux, binding to
host [::] will accept IPv4 or IPv6 connections.

The Net::Server::Proto::object method returns a list of objects corresponding
to created sockets. For Unix and INET sockets the list typically contains
just one element, but may return multiple objects when multiple protocol
families are allowed or when a host name resolves to multiple local
binding addresses.  This is particularly true when an ipv value of '*' is
passed in allowing hostname resolution.



( run in 0.281 second using v1.01-cache-2.11-cpan-5f2e87ce722 )