Search |
||
Grizzly : How to be notify when a client disconnectPosted by survivant on November 25, 2008 at 7:56 AM PST
It's now possible to be notify when a client disconnect for a server build on Grizzly 1.9+. here a little snippets that will allow you that. Thanks to the new ConnectionCloseHandler. public void init(){ public void locallyClosed(SelectionKey key) { public void remotlyClosed(SelectionKey key) { »
Related Topics >>
Open Source Comments
Comments are listed in date ascending order (oldest first)
Submitted by heaththegreat on Wed, 2008-11-26 09:32.
How is this feature implemented?
Do you report a local connection close event when someone requests the socket to close, and report a remote connection close event when you get an exception during a read?
Submitted by survivant on Wed, 2008-11-26 10:27.
Answer from Jean-Francois Arcand.
When the remote client close the connection, ConnectionCloseHandler.remotlyClosed() will be invoked *first*, then locallyClosed() will follow. When the framework detect a remote connection closed, it always make sure the SelectionKey is finished properly and eventually invoke SelectionKeyHandler.close(). That's the reason why locallyClosed is always invoked after remotlyClosed.
That doesn't make a difference in the code. When a remote connection is closed, two things could happens:
(1) I/O operations return -1 (read/write)
(2) I/O operations throws IOException (Win32)
in both case the remotlyClosed() will be called.
If you have more questions, We should continue that in the mailing list : users@grizzly.dev.java.net like that everyone will benefits of the conversation.
|
||
|
|