TsgcWebSocketServer_HTTPAPIEvents › 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: TsgcWSHTTPAPITCPConnect;
// TsgcWSHTTPAPITCPConnect = procedure(Connection: TsgcWSConnection; var Accept: Boolean) of object

Default Value

Remarks

OnTCPConnect is called AFTER the TCP connection is accepted by HTTP.SYS and BEFORE the WebSocket handshake is processed. Use it to inspect Connection.PeerIP or other socket properties and decide whether to proceed. Set Accept to False to reject the connection immediately; leave it True (the default) to let the server proceed with the WebSocket handshake or the normal HTTP request pipeline.

Example


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

Back to Events