#1 2015-06-19 11:04:50

hnb
Member
Registered: 2015-06-15
Posts: 291

Android TSQLHttpClientWinSock connect problem

Hi,

I am using mORMot for Android client (FPC 3.1.1 r30739). I have problem when server is unavailable (for TSQLHttpClientWebsockets/TSQLHttpClientWinSock).

  aClient := TSQLHttpClientWebsockets.Create(cfg.IP, cfg.Port, aModel);
  aPerson := TSQLperson.Create(aClient, someID); // this line is freezing application for more than 60 sec 

In windows client all works fine (the client application does not stop on the line mentioned above). Anyway i found solution (maybe not perfect but now is possible to set timeout in overloaded constructor in TSQLHttpClientWinSock). Patch attached:

https://drive.google.com/file/d/0B4PZhd … sp=sharing

best reagrds,
Maciej Izak

Last edited by hnb (2015-06-19 11:05:18)


best regards,
Maciej Izak

Offline

#2 2015-06-19 11:54:47

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

Re: Android TSQLHttpClientWinSock connect problem

Should be included by http://synopse.info/fossil/info/ce16c554f7

Thanks for the input!

Offline

#3 2015-06-19 12:38:21

hnb
Member
Registered: 2015-06-15
Posts: 291

Re: Android TSQLHttpClientWinSock connect problem

Why you have added ConnectTimeout optional parameter only for TSQLHttpClientRequest? I need ConnectTimeout for TSQLHttpClientWebsockets/TSQLHttpClientWinSock smile.


best regards,
Maciej Izak

Offline

#4 2015-06-19 13:25:06

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

Re: Android TSQLHttpClientWinSock connect problem

Offline

#5 2015-06-19 20:10:39

hnb
Member
Registered: 2015-06-15
Posts: 291

Re: Android TSQLHttpClientWinSock connect problem

Now works perfect. Even SendTimeout and ReceiveTimeout in TSQLHttpClientWinSock.InternalCheckOpen is now covered.

Thanks.


best regards,
Maciej Izak

Offline

#6 2016-09-28 07:11:52

AOG
Member
Registered: 2014-02-24
Posts: 490

Re: Android TSQLHttpClientWinSock connect problem

@hnb
According to your experience, what are sensible values for the three timeouts on Android ?

Offline

#7 2016-09-28 07:44:55

hnb
Member
Registered: 2015-06-15
Posts: 291

Re: Android TSQLHttpClientWinSock connect problem

@AOG

From my experience the best values for release for production (in WiFi network) are:

const
  DEFAULT_CONNECT_TIMEOUT = 3000;

...

    AClient := TSQLHttpClientWinSock.Create(AIP, APort, GModel,
      SynCrtSock.HTTP_DEFAULT_SENDTIMEOUT, SynCrtSock.HTTP_DEFAULT_RECEIVETIMEOUT, DEFAULT_CONNECT_TIMEOUT);

In addition if connection is successful I have dedicated thread (and client GClientPing - created with the same parameters as presented above) for ping purposes (online/offline status):

const
  PING_MS_DELTA = DEFAULT_CONNECT_TIMEOUT;  

...

class function TSyncProcess.TSync.Ping: Boolean;
var
  LNow, LThen: TDateTime;
  LTryPing: Boolean;
begin
  LNow := TimeLogToDateTime(GClientPing.ServerTimeStamp);
  LThen := TimeLogToDateTime(FLastPingTimeStamp);

  LTryPing := (FLastPingTimeStamp = 0) or (MilliSecondsBetween(LNow, LThen) > PING_MS_DELTA);

  if LTryPing or FLastPingResult then
  begin
    try
      Result := GClientPing.ServerTimeStampSynchronize;
    except
      Result := False;
    end;

    Result := Sync.StatusCodeIsSuccess(GClientPing) and Result;
    FLastPingResult := Result;
    FLastPingTimeStamp := GClientPing.ServerTimeStamp;
  end
  else
    Result := FLastPingResult;
end;  

best regards,
Maciej Izak

Offline

#8 2016-09-29 06:23:03

AOG
Member
Registered: 2014-02-24
Posts: 490

Re: Android TSQLHttpClientWinSock connect problem

@hnb
Thanks for your info. Will use your settings.
(about your code-snippet: nice, but why a class function with a GClientPing that must have been created somewhere ?)

While we are discussing Android, I have a few more Android related questions. I would appreciate your opinion.

How do you handle off-line functionality ?
I am now doing the following:
On the Android device itself, I have a slave database that is a slave of the remote master database.
The app always connects with this slave, unless there is a connection available with the master.
Problem: the slave database can be read by anybody with some hacking knowledge (master is safe and can be ecrypted).
Main question:
How to handle off-line behavior in a secure way, while not loosing to much functionality ?
On mobile, off-line behavior is very important !

Offline

#9 2016-09-30 08:13:05

hnb
Member
Registered: 2015-06-15
Posts: 291

Re: Android TSQLHttpClientWinSock connect problem

@AOG:

GClientPing is a global variable and is created together with regular clients (at application startup). I need that because  TSQLHttpClientWinSock is not thread safe. I have few threads in application:

1. GUI
2. Data sync
3. Ping

About security: I have private WiFi network in each place where my application is used. Additionally is used standard hcSynShaAes for data compression.

About functionality, look at new topic:

http://synopse.info/forum/viewtopic.php?id=3569

Last edited by hnb (2016-09-30 21:45:14)


best regards,
Maciej Izak

Offline

Board footer

Powered by FluxBB