#1 2021-01-23 23:52:53

RaelB
Member
Registered: 2010-08-04
Posts: 57

General purpose Websockets client?

Hi,

I have looked at this example of using a Websocket client: "WebSockets Client side" (https://synopse.info/forum/viewtopic.php?id=5291)

It shows using THttpClientWebSockets, and "upgrading" to use TWebSocketProtocolChat. Is this something that can only be used with a compatible mORMot Websockets server?

I am wanting to connect to an "aria2" websocket server. (It is an open source download manager. See https://aria2.github.io/manual/en/html/ … interface). Is this something I can do with mORMot websockets?

Thanks
Rael

Offline

#2 2021-01-24 13:27:21

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

Re: General purpose Websockets client?

Yes, with the THttpClientWebSockets, you can use any kind of WebSockets protocol.
Create your own protocol class, like TWebSocketProtocolChat, with the proper name.
Then assign the input/output frame events.

Offline

#3 2021-01-25 14:51:43

RaelB
Member
Registered: 2010-08-04
Posts: 57

Re: General purpose Websockets client?

I'm having trouble when calling fWebSockets.WebSocketsUpgrade

My code looks like this:

const
  fServerURI = 'localhost';
var
  fWebSocketsUri: RawUTF8;
  msg: RawUTF8;
begin
  fWebSockets := THttpClientWebSockets.Create;

  fWebSockets.Open(fServerURI, '6800');
  proto := TWebSocketProtocolChat.Create('aria2', '', OnFrameReceived);

  fWebSocketsUri := StringToUTF8('ws://localhost:6800/jsonrpc');
  msg := fWebSockets.WebSocketsUpgrade(fWebSocketsUri, '', True, false, proto);
  if msg = '' then
    Memo1.Lines.Add( 'ConnectToWebSockets: upgraded with protocol "aria2"')
  else
    Memo1.Lines.Add('Error: WebSocketsUpgrade: ' + msg);
end;

When  fWebSockets.WebSocketsUpgrade is called I get an error:
"WebSocketsUpgrade: Invalid HTTP Upgrade Header"

Can you take a look, I prepared a demo project. To run the aria server just click on prompt.bat.
http://www.bauerapps.com/dev/AriaWebSocketsTest.zip

I will buy you a coffee...

Offline

Board footer

Powered by FluxBB