<div dir="ltr">One more observation - in case network connection is completely lost in between client and server, &quot;close&quot; notifiers are not invoked at all (tried by shutting down network connection on the client machine keeping browser tab opened). In this case there is no opportunity for a client to send a close frame to the server. Is it a bug then? Using Undertow 1.2.0.Beta1</div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Oct 21, 2014 at 4:10 PM, Vladimir Tsukur <span dir="ltr">&lt;<a href="mailto:flushdia@gmail.com" target="_blank">flushdia@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Thanks Stuart,<div><br></div><div>Did not see this method in 1.0.x since it was added at a later release - tried with latest version and it works well.</div><div><br></div><div>However, I figured out that connection termination works well iif receive setter is set:</div><div><br></div><div>    WebSocketChannel channel = ...;</div><div>    channel.getReceiveSetter().set(new AbstractReceiveListener() {});<br></div><div>    channel.addCloseTask(new ChannelListener&lt;WebSocketChannel&gt;() {</div><div>        @Override</div><div>        public void handleEvent(WebSocketChannel channel) {</div><div>            ...</div><div>        }</div><div>    });</div><div><br></div><div>If receive setter is not set, then close task will not be called. In my case there was no intent to receive messages from the client and just push them from the server. Receive setter was not set =&gt; connection was not closed.</div><div><br></div><div>It seems obligatory to set receive setter all the time to make the thing work. Is it intended? While it is not a big deal really, I would imagine that Undertow should handle connection termination without explicit receive setter call made by the API client.</div><div><br></div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Oct 21, 2014 at 2:08 AM, Stuart Douglas <span dir="ltr">&lt;<a href="mailto:sdouglas@redhat.com" target="_blank">sdouglas@redhat.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">WebsocketChannel.addCloseTask() should do what you are after (this is actually provided by the base AbstractFramedChannel class).<br>
<br>
Stuart<br>
<div><div><br>
----- Original Message -----<br>
&gt; From: &quot;Vladimir Tsukur&quot; &lt;<a href="mailto:flushdia@gmail.com" target="_blank">flushdia@gmail.com</a>&gt;<br>
&gt; To: <a href="mailto:undertow-dev@lists.jboss.org" target="_blank">undertow-dev@lists.jboss.org</a><br>
&gt; Sent: Tuesday, 21 October, 2014 7:20:54 AM<br>
&gt; Subject: [undertow-dev] Handling termination of WebSocket connection<br>
&gt;<br>
&gt; Let&#39;s imagine user closed browser tab and thus terminated WebSocket<br>
&gt; connection. Is there any way to run a callback method on the server-side to<br>
&gt; handle this case?<br>
&gt;<br>
&gt; The requirement is to perform necessary cleanup actions when connection is<br>
&gt; closed, regardless of the type of disconnect (normal, forced termination,<br>
&gt; etc.).<br>
&gt;<br>
&gt; (Ideally using lower level API, and not JSR 356)<br>
&gt;<br>
&gt; --<br>
&gt; Vladimir Tsukur<br>
&gt; Software Architect, Design Engineer<br>
&gt;<br>
</div></div>&gt; _______________________________________________<br>
&gt; undertow-dev mailing list<br>
&gt; <a href="mailto:undertow-dev@lists.jboss.org" target="_blank">undertow-dev@lists.jboss.org</a><br>
&gt; <a href="https://lists.jboss.org/mailman/listinfo/undertow-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/undertow-dev</a><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div dir="ltr">Vladimir Tsukur<br>Software Architect, Design Engineer</div>
</div>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div dir="ltr">Vladimir Tsukur<br>Software Architect, Design Engineer</div>
</div>