Android Question AStreams connection lost after phone idle time

Discussion in 'Android Questions' started by gruizelgruis, May 9, 2015.

  1. gruizelgruis

    gruizelgruis Member Licensed User

    Hello,

    I'm using astreams to connect to a server written in VB6.
    Everything works great. But when I leave the phone alone for 15 min or so. The connection gets terminated.

    On the VB6 server program The winsock_error routine gets fired.

    But no "AStreams_Terminated" on the app.

    As I thought is is the wlan connection on the phone that is going idle
    I tried using both
    WS.KeepAlive(True)
    WS.PartialLock
    from the PhoneWakeState

    But still the problem occurs.

    PLease help.
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Is the screen on and the activity in the foreground when it happens?

    Are you handling AsyncStreams_Error event?
     
  3. gruizelgruis

    gruizelgruis Member Licensed User

    -Yes : The screen is on, and the activity is in the foreground.
    - No : I'm not aware of teh error event. will try right away
     
  4. gruizelgruis

    gruizelgruis Member Licensed User

    When the error_event gets raised, then
    LastException.Message = libcore.io.ErrnoException: recvfrom failed...

    please advice
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    Something is breaking the connection. You should expect communication errors and correctly handle them (reconnect after a few seconds).
     
    Peter Simpson and gruizelgruis like this.
  6. gruizelgruis

    gruizelgruis Member Licensed User

    Understood. thank you
     
  7. gruizelgruis

    gruizelgruis Member Licensed User

    This did the trick for me

    Code:
    Sub AStreams_error

    '// verbindinig is verbroken. Nieuwe verbinding proberen te maken.
        Tmr.Initialize("Tmr1",3000'/ seconden wachten (wait)
        Tmr.Enabled = True
        
    ToastMessageShow("Opniew verbinden .. ",True)
    End Sub
    Sub Tmr1_Tick
        
    '// reconnecting
        Socket1.Initialize("Socket1"'// <-- dit moet
        Socket1.Connect(Var_ServerIp,Var_ServerPoort,1001)
        Tmr.Enabled = 
    False
        
    ToastMessageShow("Opniew verbinden .. ",True)
    End Sub
     
  8. gruizelgruis

    gruizelgruis Member Licensed User

    I have created some logs on this issue. It seems the connection gets lost every 15min.
    I'm still looking to prevent this from hapening.

    I'm handeling the occasionaly communication breakdown in code now, and that works fine.

    Is there a way to disable wlan powersave ?
    I think thats causing it
     
  9. Erel

    Erel Administrator Staff Member Licensed User

  10. gruizelgruis

    gruizelgruis Member Licensed User

    Thank you erel.
    That "wifilock" code does the trick.
     
  11. hogiebaer

    hogiebaer Active Member Licensed User

    why you don´t use a service for your communications ? it works great
    Than you don´t need partiallock etc..
     
  12. gruizelgruis

    gruizelgruis Member Licensed User

    Thank you hogiebaer.
    I do have all the "Astreams" code as a sevice.
    Could you post some code. Maybe I'm doing it all wrong.

    thanks in advance
     
  13. hogiebaer

    hogiebaer Active Member Licensed User

    ok. if you use your communication in services, the problem is that the wifi goto sleep (erel is right;)).
    You can use the solution from the "erel-link" or go to the settings of the phone and change the wifi state to "never go sleep".

    great success :)
     
    gruizelgruis likes this.
  14. gruizelgruis

    gruizelgruis Member Licensed User

    Hi all, Just to follow up on this.
    I found on the serverside computer
    that the network card also has an option to save energy.


    upload_2015-6-7_8-40-10.png
     
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