Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: IO::Socket *always* making connection?

by saskaqueer (Friar)
on Feb 08, 2005 at 18:32 UTC ( [id://429175]=note: print w/replies, xml ) Need Help??


in reply to 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; # another option: $socketA = new IO::Socket::INET( PeerAddr => $A_box_address, PeerPort => $A_box_port, Proto => 'tcp', ); $skipA = 1 unless defined($socketA); # yet another eval q{ $socketA = new IO::Socket::INET( PeerAddr => $A_box_address, PeerPort => $A_box_port, Proto => 'tcp', ) or die("ouch\n"); }; $skipA = 1 if ($@ eq "ouch\n"); # and still yet... eval q{ $socketA = new IO::Socket::INET ( PeerAddr => $A_box_address, PeerPort => $A_box_port, Proto => 'tcp', ) or die("ouch\n"); } or $skipA = 1;

Replies are listed 'Best First'.
Re^2: IO::Socket *always* making connection?
by wolfger (Deacon) on Feb 08, 2005 at 18:45 UTC
    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)))'

      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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://429175]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-03-28 13:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found