Android Question websockets timeout

Discussion in 'Android Questions' started by wl, Feb 19, 2015.

  1. wl

    wl Well-Known Member Licensed User

    Hi,

    I noticed websockets can detected whether the connection was closed.
    It *seems* this happens after a timeout period of around 30 seconds after the last messages that was tried being sent ?

    So If I send a keep-alive message each 10 minutes and would disconnect immediately after such a keep-alive message, it would take another 10,5 minutes for the Closed method to be called ?

    Is this correct ?

    Thank you
     
  2. Erel

    Erel Administrator Staff Member Licensed User

  3. LucaMs

    LucaMs Expert Licensed User

    Last edited: May 2, 2016
  4. Erel

    Erel Administrator Staff Member Licensed User

  5. LucaMs

    LucaMs Expert Licensed User

    Thank you, Erel
     
  6. LucaMs

    LucaMs Expert Licensed User

    I have tried in this way, in the "websocket (B4J) class":
    Code:
    Private Sub WebSocket_Connected (WebSocket1 As WebSocket)
        ws = WebSocket1
        ws.Session.MaxInactiveInterval = 
    10 ' seconds
    End Sub
    upload_2016-5-3_12-20-16.png
    So, I expect that the event WebSocket_Disconnected would be triggered after 10 seconds of client inactivity but it wasn't, the connection remains active.

    That should be the ideal solution. Otherwise, I thought about using a flag in the "websocket (B4J) class" and test it every X period using a timer, but I have to set this flag for each transaction made by the client and this is a bore (and I might forget to set it).


    P.S. and I have to search if many timers (one of each connection) degrade server performance.
     
    Last edited: May 3, 2016
  7. LucaMs

    LucaMs Expert Licensed User


    This is because "probably" ( :)) I have confused "session" with "connection" ("... the SESSION will be invalidated...").
    Indeed, in that my test the session is no longer valid after 10 seconds.

    So, I suppose there is not a way, by setting something, to disconnect a websocket automatically after x minutes of inactivity, right? Should I use timers as I wrote in the previous post?
     
    Last edited: May 3, 2016
  8. Erel

    Erel Administrator Staff Member Licensed User

    Yes, you should use a timer.
     
    LucaMs likes this.
  9. LucaMs

    LucaMs Expert Licensed User

    :(
     
  10. LucaMs

    LucaMs Expert Licensed User

    Probably (very probably :D) I'm wrong but...

    I don't know how exactly B4J "creates" a websocket class (internally) but this class provides a websocket and two websocket events, WebSocket_Connected and WebSocket_Disconnected, which correspond to Jetty websocket events.

    This document says that there is another event available, On Message; if this event was also available in the "B4J Websocket Class", I could set the flag I mentioned in #6 within the routine that handles this event, avoiding the problems I have mentioned there.

    This post is "just to say", because, if it is possible, if you can add this event, I will have to wait for the new version of B4J :(


    Thank you anyway for your previous answers, Erel :)
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice