Bug? Under some conditions jWebSocketClient doesn't really close.

Fernando Solá

Member
Licensed User
Longtime User
A third party application providing WebSocketServer connectivity may drop the connection without properly closing it (ie: when closing the program), wich in turn, the jWebSocketClient does raises the Close event, but the underlying Jetty WebSocketClient object doesn't actually close. That leads to the program not being able to gracefully exit unless ExitApplication is called. There is no way to close that object directly from the jWebSocketClient object methods and it easily triggers a Null object error when trying to close it again.

This behavior has been observed with versions 1.10 and 1.13 of the jWebSocketClient library.

The objects created with this library should be able to handle this situation since no one can predict how a 3rd party server might close the client connection; therefore the client should be able to handle it by itself.

There is a workaround to this issue using JavaObject, by getting the Jetty WebSocketClient object from the jWebSocketClient object and closing it manually, still, the WSC should be able to propperly close before the Close event is raised.
 

Fernando Solá

Member
Licensed User
Longtime User
Here it is.

WebSocketClient not closing Workaround:
Sub Process_Globals
    
    Private wsc_Object As WebSocketClient
    Private jo_WSC As JavaObject
    
End Sub

Public Sub InitializeWSC()
    
    wsc_Object.Initialize("wsc_Object")
    jo_WSC = wsc_Object.As(JavaObject).GetField("wsc")
    
End Sub

Public Sub CloseWSC()
    
    wsc_Object.Close
    
End Sub

Private Sub wsc_Object_Closed (Reason As String)
    
    Try
        jo_WSC.RunMethod("stop",Null)
    Catch
        Log(LastException)
    End Try
    
End Sub
 
Last edited:

Fernando Solá

Member
Licensed User
Longtime User
Looks like there is some confusion with this library versioning. v2.00 is an internal library and is based on a newer version of Jetty. The Close method calls the stop API. Please try it.
I will try it as soon as I can. Thank you for the tip. 👍
 
Top