You are not logged in.
Pages: 1
Hi,
I can't find the way to enable a WebSocket communication between React and a mORMot server, can someone give me an example please?
Offline
See in the '31 - WebSockets' folder the Project31SimpleEchoServer.dpr sample.
It is a low-level WebSockets server, and there is a JavaScript client.
We use such a dedicated "protocol" class for WebSockets protocol with React/Angular clients.
It is easier/more direct to work with than interface-based services, for a JS client.
Offline
Thank you very much Mr. Bouchez, it now works like a charm!
Offline
See in the '31 - WebSockets' folder the Project31SimpleEchoServer.dpr sample.
It is a low-level WebSockets server, and there is a JavaScript client.We use such a dedicated "protocol" class for WebSockets protocol with React/Angular clients.
It is easier/more direct to work with than interface-based services, for a JS client.
But is it possible to implement interfaced-based services for a JS client?
I'm asking because it's a very powerful idea to systemize all commands/events between distributed software parts. It's not cool to neglect such a good tool like interfaced-based services doing instead low level Websockets interactions (parsing, formatting etc).
Thanks.
Offline
Interface-base services are over HTTP/REST by now for JavaScript.
They are not supported yet with JavaScript.
You can create asynch interface-based services in Delphi/FPC and consume them from Delphi/FPC, but you will have to write all the low-level JSON code by hand in JS if you want to have a JS client.
Offline
Interface-base services are over HTTP/REST by now for JavaScript.
They are not supported yet with JavaScript.
You can create asynch interface-based services in Delphi/FPC and consume them from Delphi/FPC, but you will have to write all the low-level JSON code by hand in JS if you want to have a JS client.
Ab, thanks for the answer.
I have the architecture the same you mentioned: 1) Delphi 7 server, 2) Delphi 7 Client, 3) Web (HTML5, JS) client. I'd like to use a unified data communication protocol to link them. I'm looking for Websockets-oriented classes in mORMot Framework to implement iterface-based approach.
As far as I know a communication between Delphi Server and Delphi Client could be done as like in Project31LongWorkServer and Project31LongWorkClient:
-- Client: TSQLHttpClientWebsockets;
-- Server: TSQLHttpServer.
But in the Project31SimpleEchoServer it is used TWebSocketServer which is perfectly works with JS Client but is not compatible with TSQLHttpClientWebsockets.
Sorry for the long description but could you please suggest some classes that I can use to combine Delphi Server, Delphi Client and JS Client based on interface approach?
Thanks,
Andrii.
Offline
The problem is on the JS side: there is currently no easy support of our WebSocket JSON frame format.
You have to make the decoding/encoding at hand.
Thanks.
I have modified code a little changing binary protocol to json one:
Project31LongWorkServer.dpr
HttpServer.WebSocketsEnable(Server,'', True, False);
Project31LongWorkClient.dpr
Client.WebSocketsUpgrade(PROJECT31_TRANSMISSION_KEY, True, False);
Project31SimpleEchoServer.html
socket = new WebSocket("ws://localhost:8888/root", "synopsebin");
After that JS code connected to WS Server successfully.
So my last question here is could share some references where I can find details of JSON protocol? I'd like to try implementing it on JS side.
Thanks again for the perfect framework and your support.
Best regards,
Andrii.
Offline
There is no documentation about the JSON protocol itself yet.
The class implementing it is TWebSocketProtocolJSON.
See https://synopse.info/files/html/api-1.1 … OTOCOLJSON
You will find the JSON layout in the source code.
It is just a few lines.
But the higher level protocol, i.e. REST emulation over WebSockets, is implemented in TWebSocketProtocolRest.
It is the common ancestor to both TWebSocketProtocolBinary and TWebSocketProtocolJSON.
The REST emulation over WebSockets is a bit tricky, since it needs to take track of the request/answers over the wire.
Offline
Pages: 1