how to confirm the connection status before sending the data?
The only reliable way to do that is to try sending data the client socket. If the connection has been closed then the call will fail.
If the socket has been recycled (re-used by another new connection) then the SESSION_ID
(and possily the client IP address) will be different.
If the connection was "cleanly" closed (if the client used shutdown()
and waited a bit before closing) then G-WAN will know about the status of the connection before the servlet, otherwise, G-WAN will know only when sending a reply (or after a read/write timeout).
To help with the kind of cases described by this question, a new state called BEFORE_CLOSE
has been added a few weeks ago for someone working on Websockets.