vancetech has asked for the wisdom of the Perl Monks concerning the following question:

According to the IO::Socket::INET manual, MultiHomed set to ON will "Try all adresses for multi-homed hosts".

I have one example here where a host is multihomed, and 5 out of 6 addresses refuse connections to the web port. The socket connection this module builds does not try all the hosts for a connection as demonstrated in my test script. Am I doing something wrong in trying to use this option?

#!/usr/bin/perl use IO::Socket::INET; my $sock = IO::Socket::INET->new( Proto => 'tcp', MultiHomed => 1, Blocking => 1, Type => SOCK_STREAM, ); $sock->connect( 80, inet_aton('alistapart.com') ); if( defined $sock && $sock->connected ) { $sock->send(qq{GET / HTTP/1.0\r\n\r\n}); $sock->recv($buffer, 1024); print $buffer . "\n"; } else { print "$!\n"; }

Replies are listed 'Best First'.
Re: Using MultiHomed not working in IO::Socket::INET?
by ikegami (Patriarch) on May 24, 2006 at 21:07 UTC

    Looking at the code, MultiHomed only works when an addresses is specified in PeerAddr/PeerHost (as opposed to using connect like you did), and it only works when a domain name is specified (as opposed to an IP address like you did). Try:

    #!/usr/bin/perl use IO::Socket::INET; my $sock = IO::Socket::INET->new( Proto => 'tcp', PeerAddr => 'alistapart.com', PeerPort => 'http', MultiHomed => 1, Blocking => 1, Type => SOCK_STREAM, ) or die("Unable to connect: $!\n"); $sock->send(qq{GET / HTTP/1.0\r\n\r\n}); $sock->recv($buffer, 1024); print $buffer . "\n";
      That works now, thanks.