TsgcWebSocketClient | Client Exceptions

Sometimes there are some errors in communications, server can disconnect a connection because it's not authorized or a message hasn't the correct format... there are 2 events where errors are captured

OnError

This event is fired every time there is an error in WebSocket protocol, like invalid message type, invalid utf8 string...


procedure OnError(Connection: TsgcWSConnection; const Error: string);
begin
  WriteLn('#error: ' + Error);
end;

 

OnException

This event is fired every time there is an exception like write a socket is not active, access to an object that not exists

 


procedure OnException(Connection: TsgcWSConnection; E: Exception);
begin
  WriteLn('#exception: ' + E.Message);
end;

By default, when connection is closed by server, an exception will be fired, if you don't want that these exceptions are fired, just disable in Options.RaiseDisconnectExceptions.