You are not logged in.
Pages: 1
Is it possible to enbable websockets from MVCApplication?
Something like this:
aServer := TSQLRestServerDB.Create(aModel,ChangeFileExt(ExeVersion.ProgramFileName,'.db'));
aApplication := TBlogApplication.Create;
try
aApplication.Start(aServer);
aServer.ServiceMethodRegisterPublishedMethods('', aApplication);
aHTTPServer := TSQLHttpServer.Create('8092',aServer,'+',useBidirSocket);
aHTTPServer.WebSocketsEnable(aServer,'').Settings.SetFullLog;
...
IChatService = interface(IServiceWithCallbackReleased)
['{D3108D0F-AC2A-4520-B3C3-A0F3695ECEBC}']
procedure Join(const callback: IChatCallback);
procedure Post(const msg: string);
end;
...
initialization
TInterfaceFactory.RegisterInterfaces([
TypeInfo(IChatService),TypeInfo(IChatCallback)]);
and then subscribe from javascript
socket = new WebSocket("ws://localhost:8092/blog/chat/join","synopsejson");
Offline
Yes, but then you will have to emulate the "synopsejson" protocol over the wire...
See TWebSocketProtocolJSON.FrameCompress and TWebSocketProtocolJSON.FrameDecompress for how the JSON content is encoded for incoming and outgoing frames, and how REST is emulated.
It is very powerful, but perhaps a bit complicated to implement from scratch. There is no JavaScript code available for it yet.
As an alternative, you could define your own WS protocol, the use it via JS WebSocket(). You can add some custom protocols to your main TWebSocketServerRest instance as created by the useBidirSocket mode.
You will have input/output JSON frames with no encapsulation.
See the WS chat sample.
I guess this is the easiest to do with a JS client.
Offline
Thank you, the second option is what I need. I'll try that way.
Offline
Pages: 1