First times working with HTTPAPI Server, it's very common that you will see that OnDisconnect event is not fired just when client closes connection. The reason is that HTTPAPI Server works a bit differently than other servers like Indy. In Indy server there is a thread for every connection and this thread is checking every x milliseconds if connection is active. The HTTPAPI Server uses a thread-pool that handles all connections and it's not checking for every connection if it's active or not.
In order to get notified when client closes connection, do the following configuration:
1. If you use a TsgcWebSocketClient, set Options.CleanDisconnect := True. This means that before the connection is closed, the client will try to send a notification to server that connection will be closed. If the server receives this message, OnDisconnect event will be called.
2. For the others disconnections, the only solution is write something to the socket and if fails means the connection is disconnected. Enable HeartBeat on HTTPAPI server, and send an interval of 60 seconds for example and a timeout of 0. This configuration means that every 60 seconds all connections will be ping and if any is disconnected, OnDisconnect event will be fired. You can put a lower value of HeartBeat.Interval, but don't put it too low (1 second for example it's too low) because the performance of the server will be affected.