You are not logged in.
Pages: 1
Hi,
I have build notification to my server / client. It's basically like samples Project31ChatClient / Project31ChatServer
Now I learned that we need to get external node.js application to receive and send notifications.
Can this be done or do i have to write some kind of server to middle?
thanks,
mika
Offline
This sample is a not standard WebSockets client or server.
There is a REST compatibility layer, HTTP-like marshalling and a callback mechanism with internal IDs...
Nothing which works with node.js !
To define a Delphi Client of a node.js on the other end, as server, you need just the raw WebSocket / json protocol.
Something like this to connect to aNodeServer:aNodePort/aNodeURI with aNodeProtocol:
ws := THttpClientWebSockets.Create;
try
ws.Open(aNodeServer, aNodePort);
info := ws.WebSocketsUpgrade(aNodeUri, '', false, false,
TWebSocketProtocolChat.Create(aNodeProtocol, '', OnIncomingFrame));
// see OnIncomingFrame below
assert(info = '');
....
// to send a frame asynchrously:
ws.WebSockets.Outgoing.Push(frame);
....
finally
ws.Free;
end;
Incoming frames will be received from this event:
procedure TMyService.OnIncomingFrame(Sender: THttpServerResp;
const Frame: TWebSocketFrame);
begin // just log and add the frame to a list
fLog.Log(sllDebug, 'OnIncomingFrame session=% % len=% %', [fSession,
ToText(Frame.opcode)^, length(Frame.payload), Frame.PayLoad], self);
if Frame.opcode = focText then
fFrames.Add(Frame.payload);
end;
Warning: OnIncomingFrame will be executed in the websocket thread, not the main thread: don't call directly the VCL!
Offline
Thanks for reply.
I'll have to look these more closelly.
There is still much for me to understand from websockets ...
Offline
Hello Arnaud
I was looking at the Synopse Websockets implementation in SynbidirSock, because I need a Winsockets Client that could connect to a standard external winsockets server, not an interface based one.
The Project31SimpleEchoServer project shows how to make a server with a custom protocol, but not a client.
I found this topic, but it seems that the class implementations have changed since you posted the example. WebSocketsUpgrade does not accept a custom protocol, there are no such methods "ws.WebSockets.Outgoing.Push(frame)", etc.
Can you tell me how to make a client with a custom protocol, e.g the TWebSocketProtocolChat protocol?
And what would be the recommended way to send a frame from this client? I saw that TWebSocketProcess has a SendFrame method, but it is protected. Should I override it in my own class or what?
Thanks in advance.
Vladimir
This sample is a not standard WebSockets client or server.
To define a Delphi Client of a node.js on the other end, as server, you need just the raw WebSocket / json protocol.
Something like this to connect to aNodeServer:aNodePort/aNodeURI with aNodeProtocol:ws := THttpClientWebSockets.Create; try ws.Open(aNodeServer, aNodePort); info := ws.WebSocketsUpgrade(aNodeUri, '', false, false, TWebSocketProtocolChat.Create(aNodeProtocol, '', OnIncomingFrame)); // see OnIncomingFrame below assert(info = ''); .... // to send a frame asynchrously: ws.WebSockets.Outgoing.Push(frame); .... finally ws.Free; end;
Offline
Never mind. After a more careful look at the github commit history, it turned out that my copy of the repo is older and does not have the necessary methods. The example seems correct.
My version is 1.18.2975, installed automatically with the Delphinus plugin. While the latest one on Github is 1.18.4951.
Doesn't Delphinus install the latest that is found in Github? Should I not use it to install mormot if it falls behind?
Offline
Sorry about the spam
I found out why the Delphinus version is so old. According to the docs https://github.com/Memnarch/Delphinus/w … ur-package, it installs the latest release tag, which in mormot's case is 1.18.2975, from Sep 2016.
If there are no releases, it installs the latest commit.
If you don't plan to tag releases often, I will just install from the repo manually.
My version is 1.18.2975, installed automatically with the Delphinus plugin. While the latest one on Github is 1.18.4951.
Doesn't Delphinus install the latest that is found in Github? Should I not use it to install mormot if it falls behind?
Offline
We didn't know about the release tag thing for Delphinus...
I have made a new release, since today's trunk since stable enough.
See https://github.com/synopse/mORMot/relea … /1.18.4952
Offline
Thanks.
Offline
Pages: 1