ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> perl-xml
perl-xml
Re: RPC::XML set request timeout...
by Ulisses Reina Montenegro other posts by this author
Nov 24 2005 4:21AM messages near this date
view in the new Beta List Site
Re: RPC::XML set request timeout... | LibXML, LibXSLT free(): invalid pointer error
& XSLT On Thursday 24 November 2005 08:40, Metsinis, Aristotelis, VF-GR wrote:
>  I would like to develop an application that makes use of the RPC::XML
>  module. Is there any way of setting a timeout parameter for the request I
>  am making to a server, in order to detect a situation where the server URL
>  is not correct or the server is down for example? Please take a look at the
>  following part of the developed code...
> 
>  my $client = RPC::XML::Client->new($SERVER_URL);
>  my $request =
>  RPC::XML::request->new("BalanceInquiry",RPC::XML::struct->new('MSISDN'=>
>  RPC::XML::string->new($MSISDN),)); my $result =
>  $client->simple_request($request);
> 
>      if (ref($result))
>      {
> 
>          my $code=$result->{'RETURNCODE'};
>          print $code."\n";
>      }
>      else
>      {
>          print $result."\n";
>      }
> 
>  the above code block is enclosed within an eval but if for example I set an
>  incorrect URL on purpose, nothing seems to happen...

From "perldoc -f alarm":

eval {
	local $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n required
	alarm $timeout;
	$nread = sysread SOCKET, $buffer, $size;
	alarm 0;
};
if ($@) {
	die unless $@ eq "alarm\n";   # propagate unexpected errors
	# timed out
} else {
	# didnâ??t
}

Since in your situation you are already enclosing the code section in an eval 
block, it would be a simple matter of setting up an alarm (and corresponding 
signal handler) before calling any remote acess method with the appropriate 
value, and checking if you received a timeout message in your error checking 
code after the eval block.

Cheers
Ulisses

>  ---------------------------------------------------------------------------
> ----------------- Aristotelis Metsinis
>  Data Messaging Services Engineer
>  Technology Division, Value Added Services Development Department
> 
>   <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office"
>  />
> 
>  Tel: +30 210 6703942
>  Fax: +30 210 6702483
>  Mobile: +30 6944 300173
> 
> 
> 
>  E-mail: aristotelis.metsinis@[...].com
> 
> 
> 
>  Vodafone Panafon S.A.
>  Registered Office: 1-3 Tzavella Str., 15231, Halandri, Greece
>  Registered in Greece No 26089/01AT/B/92/276/04
>  ---------------------------------------------------------------------------
> -----------------

_______________________________________________
Perl-XML mailing list
Perl-XML@[...].com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Thread:
Aristotelis
Randy J. Ray
Dominic Mitchell
Ulisses Reina Montenegro

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved