#1 2016-08-19 04:21:29

Peter Evans
Member
Registered: 2016-07-03
Posts: 32

Connect to server timeout from FireMonkey Android Client

My FireMonkey Android Client takes 2 minutes to timeout when the Server is not running.
I get the message "Impossible to connect to ... server'.

Is there a way to reduce that time to, say 15 seconds?

The Android Client calls:-

   mORMotClient.GetClient

That function is defined in the unit mORMotClient as :-

function GetClient(const aServerAddress, aUserName,aPassword: string;
  aServerPort: integer; const aServerRoot: string; aHttps: boolean): TSQLRestClientHTTP;
begin
  result := TSQLRestClientHTTP.Create(aServerAddress,aServerPort,
    GetModel(aServerRoot),true,aHttps); // aOwnModel=true
  try
    if (not result.Connect) or (result.ServerTimeStamp=0) then
      raise ERestException.CreateFmt('Impossible to connect to %s:%d server',
        [aServerAddress,aServerPort]);
    if not result.SetUser(TSQLRestServerAuthenticationDefault,aUserName,aPassword) then
      raise ERestException.CreateFmt('%s:%d server rejected "%s" credentials',
        [aServerAddress,aServerPort,aUserName]);
  except
    result.Free;
    raise;
  end;
end;

I changed the function TSQLRestClientHTTP.Create in unit SynCrossPlatformREST to :-

constructor TSQLRestClientHTTP.Create(const aServer: string;
  aPort: integer; aModel: TSQLModel; aOwnModel, aHttps: boolean
  {$ifndef ISSMS}; const aProxyName, aProxyByPass: string;
  aSendTimeout, aReceiveTimeout, aConnectionTimeOut: Cardinal{$endif});
begin
  inherited Create(aModel,aOwnModel);
  fParameters.Server := aServer;
  fParameters.Port := aPort;
  fParameters.Https := aHttps;
  {$ifndef ISSMS}
  fParameters.ProxyName := aProxyName;
  fParameters.ProxyByPass := aProxyByPass;

  {fParameters.ConnectionTimeOut := aConnectionTimeOut;}
  fParameters.ConnectionTimeOut := 15000; {15sec}                <===   

  {fParameters.SendTimeout := aSendTimeout;}
  fParameters.SendTimeout := 15000; {15sec}                    <===


  {fParameters.ReceiveTimeout := aReceiveTimeout;}
  fParameters.ReceiveTimeout := 15000; {15sec}                 <=== 

  {$endif}
  fKeepAlive := 20000;
end;

However this didn't affect the timeout.

Is there some other way to achieve this?

Offline

#2 2016-08-19 08:05:13

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

Re: Connect to server timeout from FireMonkey Android Client

AFAIR the default values are  30 seconds.

   constructor Create(const aServer: string; aPort: integer; aModel: TSQLModel;
      aOwnModel: boolean=false; aHttps: boolean=false
    {$ifndef ISSMS}; const aProxyName: string='';
      const aProxyByPass: string=''; aSendTimeout: Cardinal=30000;
      aReceiveTimeout: Cardinal=30000; aConnectionTimeOut: cardinal=30000{$endif});
      reintroduce; virtual;

Do not touch the SynCrossPlatformREST unit!
But you can modify the generated mORMotClient.pas to customize the TSQLRestClientHTTP.Create() parameters as you expect.

Sounds like if the Indy library do not have the timeout parameters set.
Please check http://synopse.info/fossil/info/3101187c6f

Offline

#3 2016-09-08 02:47:14

wangming
Member
Registered: 2016-07-17
Posts: 24

Re: Connect to server timeout from FireMonkey Android Client

mORmot Framework Client Support  FireMonkey Android Client?
How do I fail to compile,
As shown below:

[DCC Fatal Error] SynCommons.pas(773): F2613 Unit 'Contnrs' not found.

Offline

#4 2016-09-09 04:07:51

Peter Evans
Member
Registered: 2016-07-03
Posts: 32

Re: Connect to server timeout from FireMonkey Android Client

Wangming: On a FireMonkey Android client you should not reference 'SynCommons.pas'.
You should reference the CrossPlatform units.

Offline

#5 2016-09-09 11:34:02

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

Re: Connect to server timeout from FireMonkey Android Client

Offline

Board footer

Powered by FluxBB