I have managed to write a working process that connects to a given IP address, sends a very basic xml string onto the host and receives a response back.
All well and good. Now I would like to add a fallback ip address that the process can call upon if it has a problem with the normal ip.
I thought about controlling this from my calling process (template-toolkit), but to do that I should return something worthwhile from here if the process fails... I guess I just don't know enough about the die command...
Please can someone help me amend this so I can get it to work? I have included my code so far...
the timeout property in my IO::Socket::INET does nothing.
Thanks in advance, here is the code...
All well and good. Now I would like to add a fallback ip address that the process can call upon if it has a problem with the normal ip.
I thought about controlling this from my calling process (template-toolkit), but to do that I should return something worthwhile from here if the process fails... I guess I just don't know enough about the die command...
Please can someone help me amend this so I can get it to work? I have included my code so far...
the timeout property in my IO::Socket::INET does nothing.
Thanks in advance, here is the code...
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 $self = shift;
my %params = (ref $_[0] eq 'HASH') ? %{$_[0]} : @_;
# important adding new line char to reqXML
my $reqXML = $params{myReqXML} . \n;
#open socket
my $sock = new IO::Socket::INET (PeerAddr => $params{myURL},
PeerPort => $params{myPort},
Proto => 'tcp',
Timeout => 3,);
die "Could not create socket: $!\n" unless $sock;
$resp="";
# send xml request
print $sock "$reqXML";
#receive and print response
$sock->autoflush(1); # so output gets there right away
while (defined ($myline = <$sock>)) {
# print $myline;
$resp = $resp . $myline;
}
close($sock);
return $resp;
};
1;