#1 2018-03-06 11:37:38

MikaK
Member
Registered: 2016-11-09
Posts: 14

Node.js client to IServiceWithCallbackReleased

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

#2 2018-03-06 19:32:37

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: Node.js client to IServiceWithCallbackReleased

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

#3 2018-03-13 06:23:50

MikaK
Member
Registered: 2016-11-09
Posts: 14

Re: Node.js client to IServiceWithCallbackReleased

Thanks for reply.
I'll have to look these more closelly. 
There is still much for me to understand from websockets ...

Offline

#4 2019-01-11 07:26:29

Vladimir
Member
Registered: 2012-12-21
Posts: 10

Re: Node.js client to IServiceWithCallbackReleased

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

ab wrote:

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

#5 2019-01-11 08:15:31

Vladimir
Member
Registered: 2012-12-21
Posts: 10

Re: Node.js client to IServiceWithCallbackReleased

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

#6 2019-01-11 08:38:34

Vladimir
Member
Registered: 2012-12-21
Posts: 10

Re: Node.js client to IServiceWithCallbackReleased

Sorry about the spam smile

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.

Vladimir wrote:

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

#7 2019-01-11 08:58:20

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: Node.js client to IServiceWithCallbackReleased

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

#8 2019-01-11 12:27:23

Vladimir
Member
Registered: 2012-12-21
Posts: 10

Re: Node.js client to IServiceWithCallbackReleased

Thanks.

Offline

Board footer

Powered by FluxBB