#1 2015-01-08 21:58:26

Sabbiolina
Member
Registered: 2014-05-20
Posts: 120

[INTERFACED] autoreconnect

Hi AB.

I'm making several calls to the server rest, so I keep saved interface (MAINshd).

I would like to repeat the call automatically in case of connection failure.

var
  retry: integer;
  done: boolean;
  Modd: TSQLModel;
  CLID: TSQLHttpClient;
begin
[..]

  retry: = 3;
  repeat
   done: = true;
   try
    res: = MAINshd.myInterfacedFunction ();
   except
    dec (retry);
    MAINshd: = connc (SERVER_ADDR, user, pass, modd, CLID); // Rebuild interface
    done:=retry<0;
   end;
  until done;
  [..]

end;

It works, but I was wondering if there was a smarter way.
Keep in mind that I could reconnect to another server mORMot.

Last edited by Sabbiolina (2015-01-08 22:10:37)

Offline

#2 2015-01-09 04:14:24

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,660
Website

Re: [INTERFACED] autoreconnect

There is already a similar algorithm for automatic reconnection.

Offline

#3 2015-01-09 07:15:10

Sabbiolina
Member
Registered: 2014-05-20
Posts: 120

Re: [INTERFACED] autoreconnect

Where ?

Offline

#4 2015-01-09 07:54:35

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,660
Website

Re: [INTERFACED] autoreconnect

Take a look at  TSQLRestClientURI.URI() for retry in case of time out.
And in THttpClientSocket.Request.

But we may have to do a retry for other client connections (like TSQLHttpClientWinINet and TSQLHttpClientWinHTTP).

Re-creating the connection without re-creating the TSQLRestClient instance is much better approach, especially when you have sicPerClient kind of service instance lifetime.

Offline

Board footer

Powered by FluxBB