in reply to Getting IPv6 with the Cookbook

use IO::Socket::INET qw( AF_INET ); use IO::Socket::INET6 qw( AF_INET6 ); my $server = IO::Socket->new( Domain => ($ip6 ? AF_INET6 : AF_INET), Proto => 'tcp', # Makes sense for this to be variable. LocalHost => $localHost, # You sure you want this? Rarely do. LocalPort => $socket_port, Reuse => 1, Listen => $conn, ) or die "Can't make $protocol server on port $socket_port: $@\n"; print "Running on port $socket_port.\n" if $verbose;

It makes no sense for Proto to be variable since TCP and UDP programs are quite different.

Specifying LocalHost limits the interfaces that can receive the connection. If you wish to only accept connections from the local machine, you'd set this to '127.0.0.1'. Otherwise, don't use this.

Replies are listed 'Best First'.
Re^2: Getting IPv6 with the Cookbook
by gokuraku (Monk) on Dec 20, 2007 at 13:35 UTC

    Here is the final code I generated:

    sub make_server { my ($ipv6,$localHost,$conn,$protocol,$socket_port,$verbose) = @_; my $server; print "Using protocol = $protocol on $localHost with port = $socket +_port.\n" if $verbose; if ($ipv6) { print "Running IPv6 tests.\n" if $verbose; $server = IO::Socket::INET6->new(LocalAddr => "$localHost:$soc +ket_port", Proto => $protocol, Reuse => 1, Listen => $conn) or die "Couldn't make IPv6 server on port $socket_port: $@\n"; print "Running IPv6 enabled on port $socket_port.\n" if $verbos +e; } else { print "Running IPv4 tests.\n" if $verbose; $server = IO::Socket::INET->new(LocalAddr => "$localHost:$sock +et_port", Proto => $protocol, Reuse => 1, Listen => $conn) or die "Can't make $protocol server on port $socket_port: $@\n +"; print "Running on port $socket_port.\n" if $verbose; } return($server); }

    A little about this code....it's made to use the $protocol flag to handle some test cases for TCP and UDP, the Server starts up and handles a Client that connects using similar code to start up with the same conditions. What I was trying to handle was not only IPv4 but IPv6, plus conditions for TCP and UDP so I can just send flags to the creation of the Server or Client and have them generate what I need.

    Of course none of this addresses the fact that I also need to make something with Named Pipes for Windows, but that's another story.