You are not logged in.
I have copied an existing working skeleton of a websocket client/server example I have made for my work
The copied project had one major problem:
Websocket client connects, it does everything ) need as rest client, it does not disconnect but it never gets a websocket response through the callback interface (more or less the same with the existing sample in Mormot1)
After spending a couple of hours to find what happens, I found the problem:
The orm model (used by trestserver and TRestHttpClientWebsockets) is created with a url base that contains a slash like 'base1/subbase2'
if this slash is missing, everything is ok
Is it my fault, or is it a bug?
To describe it better, I wanted to have one base 'urlbase' and two different Trestservers after that, one with authentication ('/urlbase/main') and the other without ('/urlbase/auth').
Is it possible to have a base url for the TRestHttpServer and each Trestrerver after this base url?
Last edited by dcoun (2022-08-19 08:10:04)
Offline
I don't see where the '/' is not supported.
Do you have any hint?
The same project with websocket server and client works OK if no slash exists in the URI in model's creation.
if a slash exists, REST works ok, but the client never receives the websocket responses from the server
Offline
Trying examples from mormot2/ex/rest-websockets
Running restws_longworkserver and restws_longworkclient as it is in repository
Received the following in the client
Service.TotalWorkCount=1
>20220820 14403901 " trace mormot.net.ws.client.TWebSocketProcessClient(053b4458) GetFrame frames focBinary len=102
20220820 14403901 " trace mormot.net.ws.client.TWebSocketProcessClient(053b4458) GetSubFrame(1/2) r000001 focBinary len=63
Received callback WorkFinished(help) in 5047ms
>20220820 14403901 " trace mormot.net.ws.client.TWebSocketProcessClient(053b4458) GetSubFrame(2/2) r000002 focBinary len=29
Now in line 106,in the server
Server := TRestServerFullMemory.CreateWithOwnModel([],False,'root/test');
and in line 98 in the client
Client := TRestHttpClientWebsockets.Create('127.0.0.1', '8888', TOrmModel.Create([],'root/test'),false,'','',0,0,2000);
Running them and the response in the client it is now:
Service.TotalWorkCount=1
>20220820 14424803 " trace mormot.net.ws.client.TWebSocketProcessClient(04944458) GetFrame frames focBinary len=131
20220820 14424803 " trace mormot.net.ws.client.TWebSocketProcessClient(04944458) GetSubFrame(1/2) r000001 focBinary len=87
20220820 14424803 " trace mormot.net.ws.client.TWebSocketProcessClient(04944458) GetSubFrame(2/2) r000002 focBinary len=34
both compiled with delphi 11.1
Offline
So it works?
No. It does NOT work
As shown above procedure TLongWorkCallback.WorkFinished never get called
Offline
Did you debug a little more to find out why and propose a pull request to fix it?
The problem is in mormot.rest.client, line 2347
The following works for me, but I am sure what you believe it is the best approach
i:=Length(fModel.Root);
root:=Copy(url,1,i);
Split(Copy(url,i+2,4096), '/', interfmethod, id);
url ,root variable are not needed any more (a delete could be more efficient) but do you need them for cleaner code?
Last edited by dcoun (2022-08-21 09:04:17)
Offline
Nice catch.
Please try https://github.com/synopse/mORMot2/commit/419cb90f
Offline
Thanks a lot @ab
Offline