{
    "mode": "perldoc",
    "parameter": "Net::Server::Proto",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Net%3A%3AServer%3A%3AProto/json",
    "generated": "2026-10-04T09:10:47Z",
    "synopsis": "NOTE: beginning in Net::Server 2.005, the default value for\nipv is IPv* meaning that if no host is passed, or\na hostname is past, all available socket types will be\nbound.  You can force IPv4 only by adding an ipv => 4\nconfiguration in any of the half dozen ways we let you\nspecify it.\nNOTE: For IPv6 Net::Server will first try and use the module\nlisted in server config ipv6package, then\n$Net::Server::ipv6package, then IO::Socket::IP, then\nIO::Socket::INET6 (which is deprecated).\n# Net::Server::Proto and its accompanying modules are not\n# intended to be used outside the scope of Net::Server.\n# That being said, here is how you use them.  This is\n# only intended for anybody wishing to extend the\n# protocols to include some other set (ie maybe a\n# database connection protocol)\nuse Net::Server::Proto;\nmy @info = Net::Server::Proto->parseinfo(\n$port,            # port to connect to\n$defaulthost,    # host to use if none found in port\n$defaultproto,   # proto to use if none found in port\n$defaultipv,     # default of IPv6 or IPv4 if none found in port\n$serverobj,      # Net::Server object\n);\nmy @rawinfo = Net::Server::Proto->getaddrinfo($host, $port, $proto);\n# returns arrayref of resolved ips, ports, and ipv values\nmy $sock = Net::Server::Proto->object({\nport  => $port,\nhost  => $host,\nproto => $proto,\nipv   => $ipv, # * (IPv*) if false (default false)\n}, $server);\n# Net::Server::Proto will attempt to interface with\n# sub modules named similar to Net::Server::Proto::TCP\n# Individual sub modules will be loaded by\n# Net::Server::Proto as they are needed.\nuse Net::Server::Proto::TCP; # or UDP or UNIX etc\n# Return an object which is a sub class of IO::Socket\n# At this point the object is not connected.\n# The method can gather any other information that it\n# needs from the server object.\nmy $sock = Net::Server::Proto::TCP->object({\nport  => $port,\nhost  => $host,\nproto => $proto,\nipv   => 6, # IPv6 - default is * - can also be '4'\n}, $server);\n# Log that a connection is about to occur.\n# Use the facilities of the passed Net::Server object.\n$sock->logconnect( $server );\n# Actually bind to port or socket file.  This\n# is typically done by calling the configure method.\n$sock->connect();\n# Allow for rebinding to an already open fileno.\n# Typically will just do an fdopen.\n$sock->reconnect();\n### Return a unique identifying string for this sock that\n# can be used when reconnecting.\nmy $str = $sock->hupstring();\n# Return the proto that is being used by this module.\nmy $proto = $sock->NSproto();",
    "sections": {
        "NAME": {
            "content": "Net::Server::Proto - Net::Server Protocol compatibility layer\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "NOTE: beginning in Net::Server 2.005, the default value for\nipv is IPv* meaning that if no host is passed, or\na hostname is past, all available socket types will be\nbound.  You can force IPv4 only by adding an ipv => 4\nconfiguration in any of the half dozen ways we let you\nspecify it.\n\nNOTE: For IPv6 Net::Server will first try and use the module\nlisted in server config ipv6package, then\n$Net::Server::ipv6package, then IO::Socket::IP, then\nIO::Socket::INET6 (which is deprecated).\n\n# Net::Server::Proto and its accompanying modules are not\n# intended to be used outside the scope of Net::Server.\n\n# That being said, here is how you use them.  This is\n# only intended for anybody wishing to extend the\n# protocols to include some other set (ie maybe a\n# database connection protocol)\n\nuse Net::Server::Proto;\n\nmy @info = Net::Server::Proto->parseinfo(\n$port,            # port to connect to\n$defaulthost,    # host to use if none found in port\n$defaultproto,   # proto to use if none found in port\n$defaultipv,     # default of IPv6 or IPv4 if none found in port\n$serverobj,      # Net::Server object\n);\n\nmy @rawinfo = Net::Server::Proto->getaddrinfo($host, $port, $proto);\n# returns arrayref of resolved ips, ports, and ipv values\n\nmy $sock = Net::Server::Proto->object({\nport  => $port,\nhost  => $host,\nproto => $proto,\nipv   => $ipv, # * (IPv*) if false (default false)\n}, $server);\n\n# Net::Server::Proto will attempt to interface with\n# sub modules named similar to Net::Server::Proto::TCP\n# Individual sub modules will be loaded by\n# Net::Server::Proto as they are needed.\n\nuse Net::Server::Proto::TCP; # or UDP or UNIX etc\n\n# Return an object which is a sub class of IO::Socket\n# At this point the object is not connected.\n# The method can gather any other information that it\n# needs from the server object.\nmy $sock = Net::Server::Proto::TCP->object({\nport  => $port,\nhost  => $host,\nproto => $proto,\nipv   => 6, # IPv6 - default is * - can also be '4'\n}, $server);\n\n\n# Log that a connection is about to occur.\n# Use the facilities of the passed Net::Server object.\n$sock->logconnect( $server );\n\n# Actually bind to port or socket file.  This\n# is typically done by calling the configure method.\n$sock->connect();\n\n# Allow for rebinding to an already open fileno.\n# Typically will just do an fdopen.\n$sock->reconnect();\n\n### Return a unique identifying string for this sock that\n# can be used when reconnecting.\nmy $str = $sock->hupstring();\n\n# Return the proto that is being used by this module.\nmy $proto = $sock->NSproto();\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "Net::Server::Proto is an intermediate module which returns IO::Socket style objects blessed into\nits own set of classes (ie Net::Server::Proto::TCP, Net::Server::Proto::UNIX).\n\nOnly three or four protocols come bundled with Net::Server. TCP, UDP, UNIX, UNIXDGRAM, and\nSSLEAY. TCP is an implementation of SOCKSTREAM across an INET socket. UDP is an implementation\nof SOCKDGRAM across an INET socket. UNIX uses a unix style socket file with the SOCKSTREAM\nprotocol. UNIXGRAM uses a unix style socket file with the SOCKDGRAM protocol. SSLEAY is\nactually just a layer on top of TCP but uses Net::SSLeay to read and write from the stream.\n\nThe protocol that is passed to Net::Server can be the name of another module which contains the\nprotocol bindings. If a protocol of MyServer::MyTCP was passed, the socket would be blessed into\nthat class. If Net::Server::Proto::TCP was passed, it would get that class. If a bareword, such\nas tcp, udp, unix, unixdgram or ssleay, is passed, the word is uppercased, and post pended to\n\"Net::Server::Proto::\" (ie tcp = Net::Server::Proto::TCP).\n",
            "subsections": []
        },
        "METHODS": {
            "content": "Protocol names used by the Net::Server::Proto should be sub classes of IO::Socket. These classes\nshould also contain, as a minimum, the following methods should be provided:\n\nobject\nReturn an object which is a sub class of IO::Socket At this point the object is not\nconnected. The method can gather any other information that it needs from the server object.\nArguments are defaulthost, port, and a Net::Server style server object.\n\nlogconnect\nLog that a connection is about to occur. Use the facilities of the passed Net::Server\nobject. This should be an informative string explaining which properties are being used.\n\nconnect\nActually bind to port or socket file. This is typically done internally by calling the\nconfigure method of the IO::Socket super class.\n\nreconnect\nAllow for rebinding to an already open fileno. Typically will just do an fdopen using the\nIO::Socket super class.\n\nhupstring\nReturn a unique identifying string for this sock that can be used when reconnecting. This is\ndone to allow information including the file descriptor of the open sockets to be passed via\n%ENV during an exec. This string should always be the same based upon the configuration\nparameters.\n\nNSport\nNet::Server protocol. Return the port that is being used by this module. If the underlying\ntype is UNIX then port will actually be the path to the unix socket file.\n\nNShost\nNet::Server protocol. Return the protocol that is being used by this module. This does not\nhave to be a registered or known protocol.\n\nNSproto\nNet::Server protocol. Return the protocol that is being used by this module. This does not\nhave to be a registered or known protocol.\n\nshow\nSimilar to logconnect, but simply shows a listing of which properties were found. Can be\nused at any time.\n",
            "subsections": []
        },
        "HOST": {
            "content": "The hostname may be either blank, '*', be an IPv4 address, an IPv6 address, a bare hostname, or\na hostname with IPv* specifications.\n\nhost => \"127.0.0.1\",  # an IPv4 address\n\nhost => \"::1\",        # an IPv6 address\n\nhost => 'localhost',  # addresses returned by localhost (default IPv* - IPv4 and/or IPv6)\n\nhost => 'localhost/IPv*',  # same\n\nipv  => '*',\nhost => 'localhost',  # same\n\nipv  => 6,\nhost => 'localhost',  # addresses returned by localhost (IPv6)\n\nipv  => 'IPv4 IPv6',\nhost => 'localhost',  # addresses returned by localhost (requires IPv6 and IPv4)\n\n\nhost => '*',          # any local interfaces (default IPv*)\n\nipv  => '*',\nhost => '*',          # any local interfaces (any IPv6 or IPv4)\n\nhost => '*/IPv*',     # same\n",
            "subsections": []
        },
        "IPV": {
            "content": "In addition to being able to specify IPV as a separate parameter, ipv may also be passed as a\npart of the host, as part of the port, as part of the protocol or may be specified via\n$ENV{'IPV'}. The order of precedence is as follows:\n\n1) Explicit IPv4 or IPv6 address - wins\n2) ipv specified in port\n3) ipv specified in host\n4) ipv specified in proto\n5) ipv specified in default settings\n6) ipv specified in $ENV{'IPV'}\n7) default to IPv*\n",
            "subsections": []
        },
        "PORT": {
            "content": "The port is the most important argument passed to the sub module classes and to\nNet::Server::Proto itself. For tcp, udp, and ssleay style ports, the form is generally\nhost:port/protocol, [host]:port/protocol, host|port|protocol, host/port, or port. If *host* is a\nnumerical IPv6 address it should be enclosed in square brackets to avoid ambiguity in parsing a\nport number, e.g.: \"[::1]:80\". Separating with spaces, commas, or pipes is also allowed, e.g.\n\"::1, 80\". For unix sockets the form is generally socketfile|unix or socketfile.\n\nTo help overcome parsing ambiguity, it is also possible to pass port as a hashref (or as an\narray of hashrefs) of information such as:\n\nport => {\nhost  => \"localhost\",\nipv   => 6, # could also pass IPv6 (* is default)\nport  => 20203,\nproto => 'tcp',\n}\n\nIf a hashref does not include host, ipv, or proto - it will use the default value supplied by\nthe general configuration.\n\nA socket protocol family PFINET or PFINET6 is derived from a specified address family of the\nbinding address. A PFINET socket can only accept IPv4 connections. A PFINET6 socket accepts\nIPv6 connections, but may also accept IPv4 connections, depending on OS and its settings. For\nexample, on FreeBSD systems setting a sysctl net.inet6.ip6.v6only to 0 will allow IPv4\nconnections to a PFINET6 socket. By default on linux, binding to host [::] will accept IPv4 or\nIPv6 connections.\n\nThe Net::Server::Proto::object method returns a list of objects corresponding to created\nsockets. For Unix and INET sockets the list typically contains just one element, but may return\nmultiple objects when multiple protocol families are allowed or when a host name resolves to\nmultiple local binding addresses. This is particularly true when an ipv value of '*' is passed\nin allowing hostname resolution.\n\nYou can see what Net::Server::Proto parsed out by looking at the logs to see what logconnect\nsaid. You could also include a postbindhook similar to the following to debug what happened:\n\nsub postbindhook {\nmy $self = shift;\nforeach my $sock ( @{ $self->{server}->{sock} } ){\n$self->log(2,$sock->show);\n}\n}\n\nRather than try to explain further, please look at the following examples:\n\n# example 1 #----------------------------------\n\n$port      = \"20203\";\n$defhost  = \"default-domain.com\";\n$defproto = undef;\n$defipv   = undef;\n@info = Net::Server::Proto->parseinfo($port,$defhost,$defproto,$defipv);\n# @info = {\n#     host  => 'default-domain.com',\n#     port  => 20203,\n#     proto => 'tcp', # will use Net::Server::Proto::TCP\n#     ipv   => *, # IPv*\n# };\n\n# example 2 #----------------------------------\n\n$port      = \"someother.com:20203\";\n$defhost  = \"default-domain.com\";\n$defproto = \"tcp\";\n$defipv   = undef;\n@info = Net::Server::Proto->parseinfo($port,$defhost,$defproto,$defipv);\n# @info = {\n#     host  => 'someother.com',\n#     port  => 20203,\n#     proto => 'tcp', # will use Net::Server::Proto::TCP\n#     ipv   => *,\n# };\n\n# example 3 #----------------------------------\n\n$port      = \"someother.com:20203/udp\";\n$defhost  = \"default-domain.com\";\n$defproto = \"tcp\";\n$defipv   = undef;\n@info = Net::Server::Proto->parseinfo($port,$defhost,$defproto,$defipv);\n# @info = {\n#     host  => 'someother.com',\n#     port  => 20203,\n#     proto => 'udp', # will use Net::Server::Proto::UDP\n#     ipv   => *,\n# };\n\n# example 4 #----------------------------------\n\n$port      = \"someother.com:20203/Net::Server::Proto::UDP\";\n$defhost  = \"default-domain.com\";\n$defproto = \"TCP\";\n$defipv   = 4;\n@info = Net::Server::Proto->parseinfo($port,$defhost,$defproto,$defipv);\n# @info = {\n#     host  => 'someother.com',\n#     port  => 20203,\n#     proto => 'Net::Server::Proto::UDP',\n#     ipv   => 4,\n# };\n\n# example 5 #----------------------------------\n\n$port      = \"someother.com:20203/MyObject::TCP\";\n$defhost  = \"default-domain.com\";\n$defproto = \"tcp\";\n@info = Net::Server::Proto->parseinfo($port,$defhost,$defproto);\n# @info = {\n#     host  => 'someother.com',\n#     port  => 20203,\n#     proto => 'MyObject::TCP',\n# };\n\n# example 6 #----------------------------------\n\n$port      = \"/tmp/mysock.file|unix\";\n$defhost  = \"default-domain.com\";\n$defproto = \"tcp\";\n$defipv   = undef;\n@info = Net::Server::Proto->parseinfo($port,$defhost,$defproto,$defipv);\n# @info = {\n#     host  => '*', # irrelevant for UNIX socket\n#     port  => '/tmp/mysock.file', # not really a port\n#     proto => 'unix', # will use Net::Server::Proto::UNIX\n#     ipv   => '*', # irrelevant for UNIX socket\n# };\n\n# example 7 #----------------------------------\n\n$port      = \"/tmp/mysock.file|unixdgram\";\n$defhost  = \"default-domain.com\";\n$defproto = \"tcp\";\n$defipv   = undef;\n@info = Net::Server::Proto->parseinfo($port,$defhost,$defproto,$defipv);\n# @info = {\n#     host  => '*', # irrelevant for UNIX socket\n#     port  => '/tmp/mysock.file', # not really a port\n#     proto => 'unixdgram', # will use Net::Server::Proto::UNIXDGRAM\n#     ipv   => '*', # irrelevant for UNIX socket\n# };\n\n# example 8 #----------------------------------\n\n$port      = \"/tmp/mysock.file|SOCKSTREAM|unix\"; # legacy\n$defhost  = \"\";\n$defproto = \"tcp\";\n$defipv   = undef;\n@info = Net::Server::Proto->parseinfo($port,$defhost,$defproto,$defipv);\n# @info = {\n#     host  => '*', # irrelevant for UNIX socket\n#     port  => '/tmp/mysock.file', # not really a port\n#     proto => 'unix', # will use Net::Server::Proto::UNIX\n#     unixtype => 'SOCKSTREAM',\n#     ipv   => '*', # irrelevant for UNIX socket\n# };\n\n# example 9 #----------------------------------\n\n$port      = \"/tmp/mysock.file|SOCKDGRAM|unix\"; # legacy\n$defhost  = \"\";\n$defproto = \"tcp\";\n$defipv   = undef;\n@info = Net::Server::Proto->parseinfo($port,$defhost,$defproto,$defipv);\n# @info = {\n#     host  => '*', # irrelevant for UNIX socket\n#     port  => '/tmp/mysock.file', # not really a port\n#     proto => 'unix', # will use Net::Server::Proto::UNIXDGRAM\n#     unixtype => 'SOCKDGRAM',\n#     ipv   => '*', # irrelevant for UNIX socket\n# };\n\n# example 10 #----------------------------------\n\n$port = \"someother.com:20203/ssleay\";\n$defhost  = \"default-domain.com\";\n$defproto = \"tcp\";\n$defipv   = undef;\n@info = Net::Server::Proto->parseinfo($port,$defhost,$defproto,$defipv);\n# @info = {\n#     host  => 'someother.com',\n#     port  => 20203,\n#     proto => 'ssleay', # will use Net::Server::Proto::SSLEAY\n#     ipv   => *,\n# };\n\n# example 11 #----------------------------------\n\n$port = \"[::1]:20203 ipv6 tcp\";\n$defhost  = \"default-domain.com\";\n$defproto = \"tcp\";\n$defipv   = undef;\n@info = Net::Server::Proto->parseinfo($port,$defhost,$defproto,$defipv);\n# @info = {\n#     host  => '::1',\n#     port  => 20203,\n#     proto => 'tcp', # will use Net::Server::Proto::TCP\n#     ipv   => 6,\n# };\n\n# example 12 #----------------------------------\n\n$port = \"[::1]:20203 tcp\";\n$defhost  = \"default-domain.com/IPv6\";\n$defproto = \"tcp\";\n$defipv   = undef;\n@info = Net::Server::Proto->parseinfo($port,$defhost,$defproto,$defipv);\n# @info = {\n#     host  => '::1',\n#     port  => 20203,\n#     proto => 'tcp', # will use Net::Server::Proto::TCP\n#     ipv   => 6,\n# };\n\n# example 13 #----------------------------------\n\n$port = \"[someother.com]:20203 ipv6 ipv4 tcp\";\n$defhost  = \"default-domain.com\";\n$defproto = \"tcp\";\n$defipv   = undef;\n@info = Net::Server::Proto->parseinfo($port,$defhost,$defproto,$defipv);\n# @info = ({\n#     host  => 'someother.com',\n#     port  => 20203,\n#     proto => 'tcp', # will use Net::Server::Proto::TCP\n#     ipv   => 4,\n# }, {\n#     host  => 'someother.com',\n#     port  => 20203,\n#     proto => 'tcp', # will use Net::Server::Proto::TCP\n#     ipv   => 6,\n# });\n\n# example 14 #----------------------------------\n\n# depending upon your configuration\n$port = \"localhost:20203\";\n$defhost  = \"default-domain.com\";\n$defproto = \"tcp\";\n$defipv   = undef;\n@info = Net::Server::Proto->parseinfo($port,$defhost,$defproto,$defipv);\n# @info = ({\n#     host  => '127.0.0.1',\n#     port  => 20203,\n#     proto => 'tcp', # will use Net::Server::Proto::TCP\n#     ipv   => 4, # IPv4\n# }, {\n#     host  => '::1',\n#     port  => 20203,\n#     proto => 'tcp', # will use Net::Server::Proto::TCP\n#     ipv   => 6, # IPv6\n# });\n\n# example 15 #----------------------------------\n\n# depending upon your configuration\n$port = \"localhost:20203\";\n$defhost  = \"default-domain.com IPv*\";\n$defproto = \"tcp\";\n$defipv   = undef;\n@info = Net::Server::Proto->parseinfo($port,$defhost,$defproto,$defipv);\n# @info = ({\n#     host  => '127.0.0.1',\n#     port  => 20203,\n#     proto => 'tcp', # will use Net::Server::Proto::TCP\n#     ipv   => 4, # IPv4\n# }, {\n#     host  => '::1',\n#     port  => 20203,\n#     proto => 'tcp', # will use Net::Server::Proto::TCP\n#     ipv   => 6, # IPv6\n# });\n\n# example 16 #----------------------------------\n\n# depending upon your configuration\n$ENV{'IPV'} = '4';\n$port = \"localhost:20203\";\n$defhost  = \"default-domain.com\";\n$defproto = \"tcp\";\n$defipv   = undef;\n@info = Net::Server::Proto->parseinfo($port,$defhost,$defproto,$defipv);\n# @info = ({\n#     host  => '127.0.0.1',\n#     port  => 20203,\n#     proto => 'tcp', # will use Net::Server::Proto::TCP\n#     ipv   => 4, # IPv4\n# });\n",
            "subsections": []
        },
        "LICENCE": {
            "content": "Distributed under the same terms as Net::Server\n",
            "subsections": []
        }
    },
    "summary": "Net::Server::Proto - Net::Server Protocol compatibility layer",
    "flags": [],
    "examples": [],
    "see_also": []
}