#1 2012-04-26 17:58:33

Junior/RO
Member
Registered: 2011-05-13
Posts: 210

How to check if mORMot server is online?

When I try to create a instance of HttpClient, if server is offline a exception is raised.

I don't know what is the best approach to wait/retry. Should I recreate the httpclient instance?

Offline

#2 2012-04-26 19:56:33

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

Re: How to check if mORMot server is online?

Yes, just like all Delphi constructor, if an exception is raised, it is safe to recreate the instance after retry.

There won't be any memory nor resource leak.

Offline

#3 2012-04-27 02:30:42

Junior/RO
Member
Registered: 2011-05-13
Posts: 210

Re: How to check if mORMot server is online?

Thanks. But, there are some another way in the framework to check if the server is online?

Offline

#4 2012-04-27 11:37:07

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

Re: How to check if mORMot server is online?

I do not see any better solution than initiating a client connection.

Otherwise, you'd have to reconnect on success. Perhaps not worth it.

Offline

#5 2013-09-29 16:44:04

Junior/RO
Member
Registered: 2011-05-13
Posts: 210

Re: How to check if mORMot server is online?

Sorry for ressurect a old topic.

ServerTimeStampSynchronize() not existed when I asked the question a year ago. This is the best approach now, right?

Offline

#6 2013-09-29 17:49:20

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

Re: How to check if mORMot server is online?

Indeed.

If you search for ServerTimeStampSynchronize() in the documentation, you will find out a good sample:

From the client point of view, it will be consumed as such:

procedure TMainForm.FormShow(Sender: TObject);
  (...)
  fModel := TSQLModel.Create([],ROOT_NAME);
  fClient := TSQLHttpClient.Create('localhost','888',fModel);
  if not fClient.ServerTimeStampSynchronize then begin
    ShowLastClientError(fClient,'Please run Project16ServerHttp.exe');
    Close;
    exit;
  end;
  if (not fClient.SetUser('User','synopse')) or
     (not fClient.ServiceRegisterClientDriven(TypeInfo(IRemoteSQL),fService)) then begin
    ShowLastClientError(fClient,'Remote service not available on server');
    Close;
    exit;
  end;
end;

Our IRemoteSQL service will be accessed in sicClientDriven mode, so here we need to initialize RESTful authentication - see 18 - with a proper call to SetUser().

Note the use of ShowLastClientError() function of mORMotUILogin unit, which is able to use our SynTaskDialog unit to report standard and detailed information about the latest error.

Offline

Board footer

Powered by FluxBB