B4J Question WebSocket_Disconnected Event

ilan

Expert
Licensed User
Longtime User
hi

i would like to ask if we should close the websocket in the WebSocket_Disconnected Event?

B4X:
Private Sub WebSocket_Disconnected
    ws.Close
End Sub

or is it not important?

taking a closer look at the ServerExamples i don't see anywhere a ws.close command but from some articles i do read that we should close the connection.
 

alwaysbusy

Expert
Licensed User
Longtime User
ok thanks for the info
It is just my assumption, maybe @Erel can confirm? I have never closed a ws in this event for several years in many web apps and never had a problem. It is possible some 'garbage collection' is done by this code I do after starting my server:

B4X:
Dim secs As Long = ABMShared.CacheScavengePeriodSeconds ' must be defined as a long, else you get a 'java.lang.RuntimeException: Method: setIntervalSec not matched.' error
    joServer.GetFieldJO("context").RunMethodJO("getSessionHandler", Null).RunMethodJO("getSessionIdManager", Null).RunMethodJO("getSessionHouseKeeper", Null).RunMethod("setIntervalSec", Array As Object(secs))
       
    Dim jo As JavaObject = srvr
    Dim connectors() As Object = jo.GetFieldJO("server").RunMethod("getConnectors", Null)
    Dim timeout As Long = ABMShared.SessionMaxInactiveIntervalSeconds*1000
    For Each c As JavaObject In connectors
        c.RunMethod("setIdleTimeout", Array(timeout))
    Next

Alwaysbusy
 
Upvote 0
Top