<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<WebSocketChannel>() {</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 => 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="gmail_extra"><br><div class="gmail_quote">On Tue, Oct 21, 2014 at 2:08 AM, Stuart Douglas <span dir="ltr"><<a href="mailto:sdouglas@redhat.com" target="_blank">sdouglas@redhat.com</a>></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 class="h5"><br>
----- Original Message -----<br>
> From: "Vladimir Tsukur" <<a href="mailto:flushdia@gmail.com">flushdia@gmail.com</a>><br>
> To: <a href="mailto:undertow-dev@lists.jboss.org">undertow-dev@lists.jboss.org</a><br>
> Sent: Tuesday, 21 October, 2014 7:20:54 AM<br>
> Subject: [undertow-dev] Handling termination of WebSocket connection<br>
><br>
> Let's imagine user closed browser tab and thus terminated WebSocket<br>
> connection. Is there any way to run a callback method on the server-side to<br>
> handle this case?<br>
><br>
> The requirement is to perform necessary cleanup actions when connection is<br>
> closed, regardless of the type of disconnect (normal, forced termination,<br>
> etc.).<br>
><br>
> (Ideally using lower level API, and not JSR 356)<br>
><br>
> --<br>
> Vladimir Tsukur<br>
> Software Architect, Design Engineer<br>
><br>
</div></div>> _______________________________________________<br>
> undertow-dev mailing list<br>
> <a href="mailto:undertow-dev@lists.jboss.org">undertow-dev@lists.jboss.org</a><br>
> <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>