You are not logged in.
Pages: 1
How to set the websockets retry settings to prevent from raising the OnWebSocketsClosed event immediately after I kill the server.
That'my my code:
  with connector do
  begin
    KeepAliveMS := 1000 * 60 * 5; //5 mins
    Compression := [hcDeflate];
    Settings.HeartbeatDelay := 3000;
    Settings.DisconnectAfterInvalidHeartbeatCount := 5;
    Settings.ClientAutoUpgrade := True;
    OnWebSocketsUpgraded := WebSocketsUpgraded;
    OnWebSocketsClosed := WebSocketsClosed;
    ServiceDefine([IService], sicShared);
    if not connector.Services.Resolve(IService, serviceIntf) then
      raise EServiceException.Create('Service unavailable');
  end;and seems that mORMot does not respects those settings.
Offline
I thought that websocket will raise on OnWebSocketsClosed event after 5 retries (DisconnectAfterInvalidHeartbeatCount) x HeartbeatDelay (3000) = 5 times x 3 seconds = 15 seconds.
Offline
If you kill the server, then the connection is closed, therefore the OnWebSocketsClosed is notified before any hearbeat is sent.
The WebSockets protocol has a "focConnectionClose" frame which is to notify the other end of graceful reconnection.
So raising OnWebSocketsClosed immediately on graceful disconnection is what is expected IMHO - it is called "on websockets closed" as its name states.
Heartbeats are just a way of checking on an idle connection - not the only way of checking the connection state.
Offline
So what is preferred method for websocket reconnection?
procedure WebSocketsClosed(  );
begin
  timerReconnect.Enabled := True;
end;
procedure WebSocketUpgraded(  );
begin
  serviceIntf.RegisterListener('xxxx', ServiceNotification);
end;  
procedure Reconnect;
begin
  if assigned(connector) then
   connector.Free;  
  ServiceNotification := nil;
  serviceIntf := nil;
  connector := TRestHttpClientWebsockets.Create('127.0.0.1', '1414', TOrmModel.Create([]), False, '', '', 0, 0, 3000);
  ServiceNotification := TServiceNotification.Create(connector, IServiceNotification);
  with connector do
  begin
    Settings.ClientAutoUpgrade := True;
    OnWebSocketsUpgraded := WebSocketsUpgraded;
    OnWebSocketsClosed := WebSocketsClosed;
    ServiceDefine([IService], sicShared);
    connector.Services.Resolve(IService, serviceIntf);
  end;
  connector.WebSocketsUpgrade('aaa');
  timerReconnect.Enabled := false;
end;
procedure timerReconnect(Sender: TObject);
begin
  try
    Reconnect;
  except
  end; 
end;is this correct way ?
Offline
@AB fantastic, zero extra code for reconnecting feature! Thank you. When do you plan to implement reconnection?
Offline
Pages: 1