TsgcWebSocketServerEvents › 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 WebSocket handshake. It is useful when the server accepts plain TCP connections: by default OnConnect is only fired after the first message is received from the client, so handle this event and set Connection.Transport to trpTCP to treat the client as a raw TCP peer from the start. Set Accept to False to reject the connection immediately; leave it True (the default) to let the server proceed with protocol detection or the WebSocket handshake.

Example


void OnTCPConnectEvent(SgcWSConnection aConnection, ref bool Accept)
{
  aConnection.Transport = trpTcp;
  Accept = true;
}

Back to Events