in reply to Using IO::Socket

The canonical way to open an IO::Socket::INET instance to do what you want is,

my $MySocket = new IO::Socket::INET->new( PeerAddr => $host, PeerPort => $port, Proto => 'tcp', # or whatever Timeout => 300); $MySocket->connected() or die "No connection to $host:$port";
Note that a socket which fails to connect does not return a false value.

After Compline,
Zaxo

Replies are listed 'Best First'.
Re^2: Using IO::Socket
by pg (Canon) on Oct 12, 2004 at 16:16 UTC
    "Note that a socket which fails to connect does not return a false value."

    This is definitely wrong, otherwise why the following worked for me:

    use IO::Socket::INET; use strict; use warnings; IO::Socket::INET->new(Proto => "tcp", PeerAddr => "123.123.123.123", P +eerPort => 123, Timeout => 10) || die "failed to connect";

    If whatever before 'or' was not evaluated to false, why should the die get evaluated, and print the message on screen for me?

      You're right. I'm not sure what got me confused about that. Socket configure can return undef.

      After Compline,
      Zaxo

Re^2: Using IO::Socket
by Earindil (Beadle) on Oct 12, 2004 at 15:53 UTC
    I was under the impression (from much reading) that the Timeout in this case only was for the opening of the connection, not on the recv or sends.