TsgcTCPClient › Events › OnError
Fires every time a non-fatal error is reported on the TCP connection.
property OnError: TsgcWSErrorEvent;
// TsgcWSErrorEvent = procedure(Connection: TsgcWSConnection; const Error: string) of object
—
OnError reports transport-level problems detected while sending or receiving data on the TCP socket, such as a failed TLS handshake, a heartbeat timeout, or an error raised while dispatching a received payload. The Error parameter contains a textual description of the failure; the Connection parameter identifies the affected session. For unhandled exceptions (socket errors, access violations...) use OnException instead. When Connection is assigned, the component closes that connection once OnError has been raised, whatever the options: the handler has normally returned by then, but with NotifyEvents set to neAsynchronous an error raised on a secondary thread is queued to the main thread and its handler can run after the connection has been closed. When Connection is nil, nothing is closed.
OnError can fire with Connection = nil, so a handler must check Connection before using it. WriteData and WriteAndWaitData report this way a message that could not be sent because the client is not connected. The Error parameter is then Data not sent, the client is not connected or its handshake has not completed. (resourcestring S_ERROR_CLIENT_NOT_CONNECTED), and the event fires on the thread that called the method, before the method returns. A write that fails after the client has reconnected is reported with Connection = nil as well, so the new connection is not closed. Set Options.RaiseDisconnectExceptions to False in code to disable the report of messages that could not be sent.
procedure OnError(Connection: TsgcWSConnection; const Error: string);
begin
WriteLn('#error: ' + Error);
end;