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

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

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


void OnTCPConnectEvent(TsgcWSConnection Connection, ref bool Accept)
{
  Accept = Connection.PeerIP != "10.0.0.1";
}

Back to Events