I checked the stream3.c
example and found that when I closed the page in the browser, the servlet, i.e. the stream3.c
, is still running about 2 rounds then terminated.
That means, the data of the last 2 rounds was lost.
Who can explain how to confirm the connection status before sending the data?
Obviously, gwan knows the connection status, otherwise it would not terminate the stream3.c
, but gwan may not know it in real time.
If there is no way to know it in real time, important data cannot be sent without double checking through this way.
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.