#1 2017-01-23 12:16:31

turrican
Member
From: Barcelona
Registered: 2015-06-05
Posts: 94
Website

mORMot Websockets consume from Javascript

Hi,

I'm trying to consume mORMot WebSocket server with Javascript client.

Do you have an aproach to do this?

Offline

#2 2017-01-23 13:02:01

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

Re: mORMot Websockets consume from Javascript

If you use json websockets SOA will work.
But there is no support yet...

Offline

#3 2017-01-23 14:14:55

turrican
Member
From: Barcelona
Registered: 2015-06-05
Posts: 94
Website

Re: mORMot Websockets consume from Javascript

Thanks AB.

BTW, I am testing Project31SimpleEchoServer with supplied Project31SimpleEchoServer.html client. This works ok.

There is some way to find all connected sockets in the server and send information to?

Offline

#4 2017-01-23 16:18:14

turrican
Member
From: Barcelona
Registered: 2015-06-05
Posts: 94
Website

Re: mORMot Websockets consume from Javascript

Solved by this way : http://pastebin.com/UrMHSneL

Another question... Chrome and Firefox returns a 401 and 400 when try to access : http://localhost:8888/whatever/

IExplorer goes well.

Last edited by turrican (2017-01-23 16:30:32)

Offline

#5 2017-01-23 20:18:45

rclaros
Member
Registered: 2016-06-21
Posts: 8

Re: mORMot Websockets consume from Javascript

turrican wrote:

Solved by this way : http://pastebin.com/UrMHSneL

Another question... Chrome and Firefox returns a 401 and 400 when try to access : http://localhost:8888/whatever/

IExplorer goes well.

If you compile with mORMot versions of October or earlier, it works correctly on all web browsers: Chrome, Firefox ... etc

That's what I tried to say here:
https://synopse.info/forum/viewtopic.php?id=3747

Last edited by rclaros (2017-01-23 20:24:32)

Offline

#6 2017-01-24 07:23:24

turrican
Member
From: Barcelona
Registered: 2015-06-05
Posts: 94
Website

Re: mORMot Websockets consume from Javascript

Thanks rclaros,

Interesting... I'm going to check why latest builds don't work with Chrome and Firefox browsers.

Offline

#7 2017-01-24 10:59:58

turrican
Member
From: Barcelona
Registered: 2015-06-05
Posts: 94
Website

Re: mORMot Websockets consume from Javascript

Problem comes this way at SynBidirSock.pas

  prot.fRemoteIP := ClientSock.RemoteIP;
  prot.fRemoteLocalhost := ClientSock.RemoteIP='127.0.0.1';
  extin := ClientSock.HeaderValue('Sec-WebSocket-Extensions');
  if extin<>'' then begin
    CSVToRawUTF8DynArray(pointer(extin),extins,';',true);
    if not prot.ProcessHandshake(extins,extout,nil) then begin
      prot.Free;
      result := STATUS_UNAUTHORIZED;
      exit;
    end;
  end;

I'm going to compare IExplorer requests with Chrome and Firefox.

Offline

#8 2017-01-24 11:10:33

turrican
Member
From: Barcelona
Registered: 2015-06-05
Posts: 94
Website

Re: mORMot Websockets consume from Javascript

Ok... I think the problem comes with the next situation :
   - Firefox and Chrome passes Sec-WebSocket-Extensions:"permessage-deflate" header to server and server do the next thing :

  extin := ClientSock.HeaderValue('Sec-WebSocket-Extensions');
  if extin<>'' then begin
    CSVToRawUTF8DynArray(pointer(extin),extins,';',true);
    if not prot.ProcessHandshake(extins,extout,nil) then begin
      prot.Free;
      result := STATUS_UNAUTHORIZED;
      exit;
    end;
  end;

Server aborts negotiation if ClientSock.HeaderValue('Sec-WebSocket-Extensions')

function TWebSocketProtocol.ProcessHandshake(const ExtIn: TRawUTF8DynArray; out ExtOut: RawUTF8;
  ErrorMsg: PRawUTF8): boolean;
begin
  result := false; // abort negotiation in case of any extension
end;

Override the ProcessHandshake method with Result := true;

So I don't know why Arnaud did this implementation. He will explain better than me.

Offline

#9 2017-01-24 14:00:04

rclaros
Member
Registered: 2016-06-21
Posts: 8

Re: mORMot Websockets consume from Javascript

Thanks turrican,

Interesting analysis you have done.

I confirm that making the change you have put in "ProcessHandshake" with "Result: = true;"
It works correctly in the web browser: "Chrome" but still does not work with "Microsoft Edge"

When comparing the SynBidirSock.pas files of the current version with the October (Works in all web browsers):
The parts of the code you have published do not exist in the October version.

Offline

#10 2017-02-03 17:39:14

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

Re: mORMot Websockets consume from Javascript

Offline

Board footer

Powered by FluxBB