#1 2024-01-25 06:10:38

keinn
Member
Registered: 2014-10-20
Posts: 100

websocket client settings.OnClientConnect has no chance to take effect

in mormot.net.ws.client,
if we get a THttpClientWebSockets instance by THttpClientWebSockets.WebSocketsConnect(a static class procudre),
then THttpClientWebSockets.Create never get executed ,
becase  THttpClientWebSockets.WebSocketsConnect use Open method to create a socket ,

so the Settings^.OnClientConnected wont take effect (no chance to set this before a connection);

Offline

#2 2024-01-25 07:39:09

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

Re: websocket client settings.OnClientConnect has no chance to take effect

Open() calls Create():

constructor TCrtSocket.Open(const aServer, aPort: RawUtf8;
  aLayer: TNetLayer; aTimeOut: cardinal; aTLS: boolean;
  aTLSContext: PNetTlsContext; aTunnel: PUri);
begin
  Create(aTimeOut); // default read timeout is 10 seconds
  // copy the input parameters before OpenBind()
  ....

And in fact, THttpClientWebSockets.Create is properly called.
Easy to reproduce with TPrivateRelay.TryConnect called from regression tests.

So I don't understand your problem.

Online

#3 2024-01-25 09:39:57

keinn
Member
Registered: 2014-10-20
Posts: 100

Re: websocket client settings.OnClientConnect has no chance to take effect

FClient :=THttpClientWebSockets.WebSocketsConnect(....),
 

use such code to create a ws client , if connection was made , the "FClient.Settings^.OnClientConnected" callback will be called (if not nil)

BUT, FClient.Settings^.OnClientConnected is nil at this time, because there is noway to set this param before create ws client,

ok , i know we can do it in the focContinuation frame, but ... just not so perfect.

Last edited by keinn (2024-01-25 09:40:24)

Offline

#4 2024-01-25 11:01:10

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

Re: websocket client settings.OnClientConnect has no chance to take effect

Why not just
- use THttpClientWebSockets.Create()
- then change the settings
- then call OpenBind()/ConnectUri(),
- then call WebSocketsUpgrade() ?

I have just added TCrtSocket.ConnectUri() which may be easier than OpenBind() to connect a client.
https://github.com/synopse/mORMot2/commit/b7e6e956

Online

Board footer

Powered by FluxBB