i am running the following code under perl 5.8.4 on a win 2000 server. what it does is this: information is passed to this routine and then is sent to 1 of 2 possible locations. the code should try to send to 1 then if the connection fails try the other one and continue to do that for a maximum of 2 times per ip. The issue i am running into is the code fails to flip-flop. If the connection fails or nothing comes back after 5 seconds i need to switch the connection to the other system. any suggestions on alternative ways to handle this task and/or any ideas why my code fails to do this properly would be a great help. thanks ahead of time for all the great wisdom that resides behind this url.
sub send_to_processor{ my $message = $_[0]; use Sys::Hostname; use Socket; my @transaction_ips = ('10.30', '10.31'); #If connection isn't open, then open it for(my $i = 0;$i < 4;$i++){ last if($remote = IO::Socket::INET->new(Proto => 'tcp', PeerAd +dr => $transaction_ips[($i%2)], PeerPort => 8120, Timeout => 5)); } #If connection still isn't open, #then connection is unavailable unless(defined $remote){ return(0, 'Server Unavailable!'); } #Send Message print $remote $message; #Recieve Response my $response; recv($remote, $response, 2048, 0); #Close Connection close $remote; return (1,$response); }

In reply to flip-flop socket locations if 1 is down by bear0053

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.