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

public event TsgcWSOnTCPConnectHandler OnTCPConnect;
// delegate void TsgcWSOnTCPConnectHandler(TsgcWSConnection Connection, out bool Accept)

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


void OnTCPConnectEvent(SgcWSConnection aConnection, ref bool Accept)
{
  Accept = aConnection.PeerIP != "192.168.0.100";
}

Back to Events