Hi, I do have more question....
I want to connect to a remote host and have a backup host if there is a problem in the connection.
I can use my template-toolkit code to call the fallback IP but there is a time delay of 30 seconds. This is too long.
I am trying to set a timeout of around 2-3 seconds and notice that the IO::Socket::INET timeout value is doing nothing.
Reading up I found some detail on using an alarm method, but my small knowledge of perl is hindering me yet again. (incorrect) syntax below,
:-(
I am sure I have been close to getting it to work somewhere along the line, but not sure where... might be the parameter variables are not being recognised in the eval...
Any help on this would be really great.
Thanks in advance
Andy
I want to connect to a remote host and have a backup host if there is a problem in the connection.
I can use my template-toolkit code to call the fallback IP but there is a time delay of 30 seconds. This is too long.
I am trying to set a timeout of around 2-3 seconds and notice that the IO::Socket::INET timeout value is doing nothing.
Reading up I found some detail on using an alarm method, but my small knowledge of perl is hindering me yet again. (incorrect) syntax below,
:-(
Code:
package plugin::SterlingDCC;
use base qw( Template::Plugin );
use Template::Plugin;
use IO::Socket;
use lib::SkyObject;
use vars qw( @ISA );
@ISA = qw( Template::Plugin lib::SkyObject );
#! /usr/bin/perl -w
#----------------
sub getResp {
my $timeout = 3;
my $self = shift;
my %params = (ref $_[0] eq 'HASH') ? %{$_[0]} : @_;
my $reqXML = $params{myReqXML} . \n;
my $resp="";
$SIG{ALRM} = \&timed_out;
eval {
alarm ($timeout);
#open socket
my $sock = new IO::Socket::INET (PeerAddr => $params{myURL},
PeerPort => $params{myPort},
Proto => 'tcp',
);
print $sock "$reqXML";
$sock->autoflush(1); # so output gets there right away
while (defined ($myline = <$sock>)) {
$resp = $resp . $myline;
}
alarm (0);
close($sock);
};
$resp;
};
sub timed_out {
return (0);
}
1;
I am sure I have been close to getting it to work somewhere along the line, but not sure where... might be the parameter variables are not being recognised in the eval...
Any help on this would be really great.
Thanks in advance
Andy