RTC Forums
April 28, 2024, 12:02:32 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Login Register  
Pages: [1]
  Print  
Author Topic: Recovering gracefully  (Read 3298 times)
ClementDoss
RTC License
***
Posts: 36


« on: November 08, 2014, 07:36:27 PM »

Hi,

I'm using rtc 6.42 and DXE7.

I'm working between tiers, mostly remote function calls.
My Server Application layer (SAL) has a start/stop button that starts/stop rtcHTTPClient.
When I start the client application, it detects correctly that the SAL is online.
I press the stop button, the client application detects the connection was lost, I display a corresponding icon.

Now the problem. The client application "knows" the connection is lost and any remote call will fail. And it fails as expected with the error:
Project erpEmpresa.exe raised exception class ERtcExecuteError with message 'Error: Connection problems, no response received.'.

I wrote a routine that is triggered when there's no connection giving some choices to the user, and I would like to trigger that same routine in this case too.

How would be the correct way to handle it?

The code looks like this:
{code}
// FClientModule : TrtcClientModule;
var
  lResult : TrtcValue;
begin
   // This code fails, and I know it will fail because the SAL is offline
   // How can I trigger my routine before executing the code below?
   lResult := FClientModule.Execute;
  {...}
{/code}


Pseudo code of what I'd like:
{code}
var
  lResult : TrtcValue;
begin
   // This is what I'm doing today. Is there a better way?
   if not FClientModule.Client.<IsCurrentlyConnected> then
     FClientModule.Client.CallOnCOnnectionLost;

   // This code should only be executed if the connection is recovered
   lResult := FClientModule.Execute;
  {...}
{/code}


Best regards,
Clément




Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #1 on: November 08, 2014, 08:24:52 PM »

If you are manually calling "Connect" and "Disconnect" (not using AutoConnect=True), you can use the "isConnected" or "isConnecting" property to check the current status of the connection. But even if the isConnected property does return TRUE, it does not guarantee a success when posting a request, because (A) the connection could already be closed but the sockets API has not "noticed" it yet, or (B) the connection could be closed but the underlying API won't report that unless you actually try to send something through, or (C) the connection could drop while you are trying to send data through. So, the only sure way of knowing that a remote function call would succeed, is to try and make the call.

I'm not sure I understand your goal, but the simplest way to handle HTTP connections is to set the AutoConnect and ReconnectOn properties to TRUE on the TRtcHttpClient component, and set the AutoRepost property on the TRtcClientModule component to the number of retry attempts you find acceptable in case of connection failures. When you set AutoConnect and ReconnectOn properties to TRUE, if a connection is not open when you make a remote function call, the Client will try to open before trying to make the remote call. And if the AutoRepost property is used (not zero), a new remote function call attempt will be made in case of a failure, without raising the exception when you use the Execute method.

Best Regards,
Danijel Tkalcec
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.023 seconds with 17 queries.