#1 2020-02-29 03:46:18

MarcusF
Member
Registered: 2017-08-18
Posts: 4

Websocket subprotocol

Hello, I'm new to mORMot and trying to create a websocket server using the simpleechoserver as an example, connection to it from a TMS Web  Core websocket client.
https://github.com/synopse/mORMot/blob/ … Server.dpr

I'm running into an issue where I can't set a subprotocol in the TMS client, is there a simple way to ignore the subprotocol with mORMot websocket server?

protocol := TWebSocketProtocolEcho.Create('meow','');

Last edited by MarcusF (2020-02-29 03:49:35)

Offline

#2 2020-02-29 13:55:46

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

Re: Websocket subprotocol

Are you sure the TMS component doesn't allow to setup the protocol?
It is weird, because the raw JS function has the parameter - see the .html file in the sample folder.

You can set the connection using either the protocol header or the URI.
Try by setting the URI.

Offline

#3 2020-02-29 21:53:03

MarcusF
Member
Registered: 2017-08-18
Posts: 4

Re: Websocket subprotocol

How do I set the protocol using the URI?

Looking at the example html, it shows two versions, the second including an empty protocol string, which results an error on connection.

socket = new WebSocket("ws://localhost:8888","");
SyntaxError: Failed to construct 'WebSocket': The subprotocol '' is invalid.

If I remove the second parameter, the subprotocol, I get this error

socket = new WebSocket("ws://localhost:8888");
onerror - code:undefined, reason:undefined, wasClean:undefined, status:3
onclose - code:1006, reason:, wasClean:false, status:3

This is why I'm wondering if there's an easy way to ignore or not check for a protocol, as it's an optional parameter for websockets.  I'm also talking to TMS, asking them why they haven't exposed that setting.

Offline

#4 2020-03-01 03:19:24

MarcusF
Member
Registered: 2017-08-18
Posts: 4

Re: Websocket subprotocol

I've fixed the issue by updating the TMS package to include a sub-protocol, but I'll open a request for improvement to update the websocket implementation to allow to not use the optional sub-protocol parameter, along with an updated example since the current one isn't running for me (The second one that doesn't include a sub-protocol)

Offline

Board footer

Powered by FluxBB