TsgcWebSocketHTTPServerEvents › OnTCPConnect

OnTCPConnect Event

Fires after a client connects at TCP level and before the WebSocket handshake, so the connection can be accepted or rejected.

Syntax

property OnTCPConnect: TsgcWSOnTCPConnect;
// TsgcWSOnTCPConnect = procedure(Connection: TsgcWSConnection; var Accept: Boolean) of object

Default Value

Remarks

OnTCPConnect is called AFTER the TCP connection is accepted and BEFORE the HTTP request is parsed or the WebSocket handshake takes place. It is the earliest opportunity to inspect Connection.PeerIP and reject unwanted clients, for example to implement per-IP rate limits. Set Accept to False to close the connection immediately, or leave it True (the default) so the server proceeds with HTTP/WebSocket protocol detection. To promote the connection to a plain TCP peer from the start, set Connection.Transport to trpTCP inside the handler.

Example


procedure OnTCPConnectEvent(aConnection: TsgcWSConnection; var Accept: Boolean);
begin
  Accept := aConnection.PeerIP <> '192.168.0.100';
end;

Back to Events