Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] Determining whether WebSocket.onClose was triggered by client or server

True, the category of close conditions around 'force close' for various things (like protocol errors, protocol violations, exceptions in the user websocket object, memory, networking, idleness, etc) will close the connection, usually with a blind send of a close frame, and then terminate of the connection.   
We can't rely on a proper handshake in many of these situations so it can't really wait on the close from the other side.
But we still have an obligation to let the user websocket object know that the connection was closed.

--
Joakim Erdfelt <joakim@xxxxxxxxxxx>
www.webtide.com
Developer advice, services and support
from the Jetty & CometD experts.



On Fri, Sep 14, 2012 at 2:01 PM, Brandon Mintern <mintern@xxxxxxxxxxx> wrote:
I wish this were the case, but it seems that Jetty's WebSocket.onClose
method fires even when Jetty closes the WebSocket internally due to
some error.

On Fri, Sep 14, 2012 at 1:57 PM, Joakim Erdfelt <joakim@xxxxxxxxxxx> wrote:
> A websocket.close is a handshake, and the implementation should notify you
> when it receives a Close frame.
> So it should be safe to assume that if you get onClose, the opposite side
> sent it.
>
> --
> Joakim Erdfelt <joakim@xxxxxxxxxxx>
> www.webtide.com
> Developer advice, services and support
> from the Jetty & CometD experts.
>
>
>
> On Thu, Sep 13, 2012 at 12:29 PM, Brandon Mintern <mintern@xxxxxxxxxxx>
> wrote:
>>
>> Is there a way to determine whether a call to onClose was triggered by
>> the client or the server?
>>
>> I'm implementing a base WebSocket class, and any time a subclass
>> throws an exception while handling a message, I close the connection
>> with an error message. When this happens, the onClose method fires.
>>
>> My base WebSocket is providing an onClientClose method to my
>> subclasses, so I'd like to know if there's an easy way to determine
>> whether a call to onClose was triggered by the _javascript_ client
>> closing the connection or by the Java/jetty server closing the
>> connection. Currently, I'm setting a flag before closing the
>> connection myself, but I've noticed that any error in jetty also
>> closes the connection and calls onClose.
>>
>> Thanks in advance,
>> Brandon
>> _______________________________________________
>> jetty-users mailing list
>> jetty-users@xxxxxxxxxxx
>> https://dev.eclipse.org/mailman/listinfo/jetty-users
>
>
>
> _______________________________________________
> jetty-users mailing list
> jetty-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/jetty-users
>
_______________________________________________
jetty-users mailing list
jetty-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/jetty-users


Back to the top