in reply to Re: IO::Socket *always* making connection?
in thread IO::Socket *always* making connection?

As such (such being that IO::Socket::INET does not die or set $@ on failure), you'd want one of the following code snippets:
# best solution: $socketA = new IO::Socket::INET( PeerAddr => $A_box_address, PeerPort => $A_box_port, Proto => 'tcp', ) or $skipA = 1;

That is exactly how my code used to look prior to encountering this problem. I thought that eval might help me catch it, but obviously no... Everybody seems to think eval is my problem now... With the code looking exactly as above, I still do not see $skipA == 1 unless I kill the program at the PeerPort. If it is simply busy with another client, $skipA stays == 0.


--
Linux, sci-fi, and Nat Torkington, all at Penguicon 3.0
perl -e 'print(map(chr,(0x4a,0x41,0x50,0x48,0xa)))'

Replies are listed 'Best First'.
Re^3: IO::Socket *always* making connection?
by saskaqueer (Friar) on Feb 08, 2005 at 19:01 UTC

    I don't see where your problem is. The following script works fine for me. My box has an smpt server listening on port 25, a pop3 server on port 110, and nothing on ports 9805 and 9806. The results are as expected.

    #!/usr/bin/perl -w use strict; use IO::Socket; for my $port (25, 9805, 9806, 110) { my $skipA = 0; my $socketA = new IO::Socket::INET( PeerAddr => 'localhost', PeerPort => $port, Proto => 'tcp', ) or $skipA = 1; print "\$port: $port; \$skipA: $skipA\n"; } __END__ $port: 25; $skipA: 0 $port: 9805; $skipA: 1 $port: 9806; $skipA: 1 $port: 110; $skipA: 0

      The problem comes not when there is nothing there (i.e. 9805/9806), but when there *is* something there, but it's busy. My program fails to retrieve any data, and also fails to say "sorry, couldn't connect, he's busy".


      --
      Linux, sci-fi, and Nat Torkington, all at Penguicon 3.0
      perl -e 'print(map(chr,(0x4a,0x41,0x50,0x48,0xa)))'
    A reply falls below the community's threshold of quality. You may see it by logging in.