I have handler that extends SimpleChannelInboundHandler. I use it for handling websocket frames. What is the best way to detect that connection was closed from client side (for browser closed or network connection crashed)? I see there are two methods in ChannelInboundHandlerAdapter: channelUnregistered and channelInactive. Can I use its for detectiong channel closing?
3 Answers
5
votes
0
votes
channelUnregistered()
is also called in case of an unsuccessful connection attempt. So channelInactive()
seems to be the better choice to listen to connection closed events.
I just saw this when implementing a reconnection strategy, where a closed connection would trigger a reconnect. channelUnregistered()
was my first choice and obviously wrong, because it would re-trigger a reconnect after each reconnect, endlessly.
Btw: I also tested with websocket connections.
-1
votes