TsgcWebSocketServerEvents › OnUnknownProtocol

OnUnknownProtocol Event

Fires when the first message does not match a known protocol so the connection can be accepted or rejected.

Syntax

property OnUnknownProtocol: TsgcWSUnknownProtocolEvent;
// TsgcWSUnknownProtocolEvent = procedure(Connection: TsgcWSConnection; var Accept: Boolean) of object

Default Value

Remarks

OnUnknownProtocol is raised when the server receives the first bytes from a connecting client and cannot recognize any of the built-in protocols (WebSocket, HTTP, SSE...). It is typically used to accept plain TCP clients. Set Accept to True to keep the session open (OnConnect will then be fired as a plain TCP connection) or to False to close it. The Connection parameter identifies the session; inspect TsgcWSConnection.Transport or the raw bytes already buffered to decide whether to allow the connection.

Example


procedure OnUnknownProtocol(Connection: TsgcWSConnection; var Accept: Boolean);
begin
  Accept := True;
end;

Back to Events