TsgcWebSocketProxyServer › Events › OnConnect
Fires every time a WebSocket connection is established with a downstream client and the proxy opens the upstream TCP session.
property OnConnect: TsgcWSConnectEvent;
// TsgcWSConnectEvent = procedure(Connection: TsgcWSConnection) of object
—
OnConnect is raised after the WebSocket handshake with a downstream client has completed successfully and the session is ready to exchange frames. At the same time the proxy opens the upstream TCP connection defined by the Proxy.Host and Proxy.Port properties and associates it with this session, so that any text or binary payload received afterwards can be forwarded upstream and any reply from the upstream server can be written back to the WebSocket client. The Connection parameter identifies the downstream session and exposes its Guid, PeerIP, protocol, authentication state, and custom tag. For plain TCP downstream connections the event is only fired after the first message is received (or after OnUnknownProtocol accepts the protocol); use OnTCPConnect instead if you need to be notified the moment the TCP socket is accepted.
procedure OnConnect(Connection: TsgcWSConnection);
begin
Log('Client connected: ' + Connection.Guid + ' from ' + Connection.PeerIP);
end;