#1 mORMot 2 » TWebSocketProcess and SendFrameJson » Yesterday 17:15:52

rcla
Replies: 0

TWebSocketProtocolChat has the SendFrameJson function.

Is it possible to add this function to TWebSocketProcess?

Something like:

function TWebSocketProcess.SendFrameJson(const Json: RawUtf8): boolean;
var
  frame: TWebSocketFrame;
begin
  frame.opcode := focText;
  frame.content := [];
  frame.tix := 0;
  FastSetRawByteString(frame.payload, pointer(Json), length(Json)); // temp copy
  result := SendFrame(frame)
end;

#2 Re: mORMot 2 » Example Echo with TWebSocketAsyncServer » 2025-12-13 16:56:33

Javierus wrote:

IMO, that kind of simple examples is prefect for anyone approaching mORMot2; what for an expert is "just ..." for a newcomer is "ah, that's what I was looking for"

IMHO, I agree with you.

Thanks.

#3 Re: mORMot 2 » Example Echo with TWebSocketAsyncServer » 2025-12-13 16:51:42

ab wrote:

Thanks for the feedback and interest.

I guess it is just
https://github.com/synopse/mORMot2/blob … server.dpr
but using THttpWebsocketAsyncServer class, isn't it?

Almost, it also has DoOnRequest which loads the file "restws_simpleechoserver.html"

#4 mORMot 2 » Example Echo with TWebSocketAsyncServer » 2025-12-13 15:58:40

rcla
Replies: 5

I have done Example of an asynchronous HTTP WebSocket Echo Server with TWebSocketAsyncServer.

Point your browser to http://localhost:8888/ for initial page using the existing file "restws_simpleechserver.html"

Full Code

What I've noticed is that when connecting for the first time, "Sender.Protocol.ConnectionID" starts at 2 or 3, not 1.

I hope this example is helpful and can be included in the official mORMot2 GitHub repository.

Thank you very much for such excellent work.

Board footer

Powered by FluxBB