#1 2012-09-26 10:13:11

h.hasenack
Member
From: Nijmegen, Netherlands
Registered: 2012-08-01
Posts: 173
Website

Message based C/S - unable to find window

So... I got http and named pipes working just fine.

Now Im trying message based C/S communication.

This is how the client is instantiated:

procedure TLCSServerMessageTest.InitRestClient(VAR aSQLRestClient: TSQLRestClientURI);
begin
  inherited;
  aSQLRestClient:=TSQLRestClientURIMessage.Create(FModel,cLCSServerName,ClassName,1000);
end;

And this is how the server is "published" from the constructor. cLCSServerName is the same const on both sides. Obvously I am missing something, but I seem to be unable to find out what.
Win7x64, DelphiXE2

constructor TLCSRestServer.Create;
begin
  FRestServersByURI := TObjectDictionary<RawUTF8,TSQLRestServerDB>.Create([]);
  FRestServersByAlias := TObjectDictionary<RawUTF8,TSQLRestServerDB>.Create([]);
  FServerModel := TLCSServerRootModel.Create(cLCSServerName);
  FServerConnProp := CreateConnectionPropertiesForConnectionString(ExpandSNGMacros(cfpLCSServerBaseDBPath));
  VirtualTableExternalRegisterAll(FServerModel, FServerConnProp);
  inherited Create(FServerModel, ExpandSNGMacros(cfpLCSServerBaseSQLiteDBPath), True);
  CreateMissingTables;

  ServiceRegister(TLCSServer,[TypeInfo(ILCSServer)],sicShared);
  ServiceRegister(TLCSAliasManager,[TypeInfo(ILCSAliasManager)],sicShared);
  ServiceRegister(TLCSClientServerSession,[TypeInfo(ILCSClientServerSession)],sicClientDriven);
  ExportServerNamedPipe(cLCSServerName);
  ExportServerMessage(cLCSServerName);
end; {- TLCSRestServer.Create }

Offline

#2 2012-09-26 11:05:43

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

Re: Message based C/S - unable to find window

... and what is the issue?

You have to register the services on the client side also.

Offline

#3 2012-09-26 11:17:48

h.hasenack
Member
From: Nijmegen, Netherlands
Registered: 2012-08-01
Posts: 173
Website

Re: Message based C/S - unable to find window

The InitRestCLient is a virtual method that allows different communications to be tested with the same base TTestCase . AMOF it's the onbly routine that is overriden in my derived testcase classes.

procedure TLCSServerTestBase.SetUp;
begin
  inherited;
  FModel := TLCSModel.Create(cLCSServerName);
  InitRestClient(FSQLRestCLient); // virtual method call

  CheckTrue(FSQLRestCLient.SetUser('Admin', 'synopse'), 'Authentication failed');
  CheckTrue(FSQLRestCLient.ServiceRegister([TypeInfo(ILCSServer), TypeInfo(ILCSAliasManager)], sicShared),'ServiceRegister failed for ILCSServer');
  CheckTrue(FSQLRestCLient.Services.Info(TypeInfo(ILCSServer)).Get(FLCSServer), 'Get(FLCSServer) failed');
  CheckNotNull(LCSServer, 'LCS Server Interface not retrieved from server');
  CheckTrue(FSQLRestCLient.Services.Info(TypeInfo(ILCSAliasManager)).Get(FLCSAliasManager), 'Get(FLCSAliasManager) failed');
  CheckNotNull(LCSAliasManager, 'LCS Aliasmanager Interface not retrieved from server');
end;

What might help is the actual error message wink

No "LCSServer" window available - server may be down

The server is defenitely not down as far as I know, as the other tests (HTTP and Name pipe) run OK.
COuld it be something stupid like an invalid window name? I found int the mormot sources that actually not the window name is set but the window class name. Also, the client seems to look for the window as classname and not the actual window name, so that looks ok.

Offline

#4 2012-09-26 14:37:14

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

Re: Message based C/S - unable to find window

In  TSQLRestServer.ExportServerMessage(), it will check for an existing fExportServerNamedPipeThread instance.
So in your case, it won't launch the GDI-based message feature.

In the current implementation, only one of the two means of communication is allowed.
This is perhaps an unnecessary limitation, since TSQLRestServer.URI() is designed to be thread-safe, so call be called by multiple protocols at once.

I've allowed TSQLRestServer.ExportServerMessage to be started in conjunction with other protocols (like named pipes).
See http://synopse.info/fossil/info/bd8fab792e

Offline

#5 2012-09-26 14:40:50

h.hasenack
Member
From: Nijmegen, Netherlands
Registered: 2012-08-01
Posts: 173
Website

Re: Message based C/S - unable to find window

Ah that's the cause.
Thx for the quck solution.

Offline

#6 2012-09-27 14:42:07

h.hasenack
Member
From: Nijmegen, Netherlands
Registered: 2012-08-01
Posts: 173
Website

Re: Message based C/S - unable to find window

I confirm this fixed.
My server app is a console app, waiting for a (console) readln to finish. This made the client app wait endlessly for a response.
I had to add a "MessageDlg" call to my server main routine, obvioulsy to ensure there is a message handling loop. Now it works fine.
I must say I actually expected the TSQLRestServer to implement the message loop...? - so: Is mormot missing a message handling loop, or is it WAD and did I miss something?

Offline

#7 2012-09-27 15:16:23

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

Re: Message based C/S - unable to find window

You should have your message loop somewhere in your code.

As stated by the documentation of ExportServerMessage:

    // - the main server instance has to process the windows messages regularely
    // (e.g. with Application.ProcessMessages)

This is by design, for any Windows applications, I suspect.
Since you should have only one message loop per application, does make sense to let the user implement it as expected.

Offline

#8 2012-09-28 06:51:04

h.hasenack
Member
From: Nijmegen, Netherlands
Registered: 2012-08-01
Posts: 173
Website

Re: Message based C/S - unable to find window

OK. Thx

Offline

#9 2012-10-01 09:06:40

h.hasenack
Member
From: Nijmegen, Netherlands
Registered: 2012-08-01
Posts: 173
Website

Re: Message based C/S - unable to find window

Just rethinking this: shouldnt there be (or is it already there) some kind of timeout on the message send/wait in the client side? Now my client "freezes", and no error is returned unti I shutdown my server.
I wouldnt want "al" my clients to freeze without an error message if my server hangs...

Offline

#10 2012-10-02 08:48:32

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

Re: Message based C/S - unable to find window

There is already a timeout property in the client access class.

Offline

#11 2012-10-03 08:37:39

h.hasenack
Member
From: Nijmegen, Netherlands
Registered: 2012-08-01
Posts: 173
Website

Re: Message based C/S - unable to find window

OK, I missed that. - Thx

Offline

Board footer

Powered by FluxBB