Android Question Intermittent timeout using PostString

Discussion in 'Android Questions' started by achtrade, Apr 9, 2015.

  1. achtrade

    achtrade Active Member Licensed User

    Hi everybody,

    I'm facing a problem with my connection. My app works fine, but suddenly, it starts with intermittent timeout using PostString after a couple minutes. My app executes a sp every 7 seconds, I'm not sure if this is the cause of my problem, if so, how can I fix it ?

    I'm only using WIFI with 2 devices Galaxy Tab 7 & Galaxy S 3. I don't think that my server has any problem.

    These are 2 errores that my app is showing:

    error: org.apache.http.conn
    ConnetTimeoutException: Connect to timed out

    error: org.apache.http
    NoHttpResponseexception: The target serverfailed to respond Job.

    Need help

    This is my relevant code:

    Sub Process_Globals
    Dim timer2 As Timer
    Private GET_MESSAGES = "get_messages"  As String  
    End Sub

    Sub Globals
    Dim SPResult As List
    End Sub

    Sub Activity_Create(FirstTime As Boolean)
    end sub
    Sub JobDone(Job As HttpJob)
    If Job.Success Then
    Dim res As String
            res = Job.GetString
    Log("Response from server: " & res)
    Dim parser As JSONParser
    Select Job.JobName
                    SPResult = parser.NextArray 
    'returns a list with maps
                     For i = 0 To SPResult.Size - 1
    Dim M As Map
                        M = SPResult.get(i)
    If M.get("id") < 0 Then
    End If
    End Select
    ToastMessageShow("Error: " & Job.ErrorMessage & " Job.JobName=" & Job.JobName, True)
    End If
    end Sub

    Sub ExecuteRemoteQuery(Query As String, JobName As String)
    Dim job As HttpJob
        job.Initialize(JobName, Me)
    "", Query)
    End Sub
    Sub GetMessages
    "CALL ListMessages", GET_MESSAGES)
    End Sub

    Sub timer2_Tick
    End Sub
    Last edited: Apr 9, 2015
  2. Peter Simpson

    Peter Simpson Expert Licensed User

    Hiya, try this sub.
    Add the following sub in the post below into your project, call the sub at the beginning of Activity_Create.

    Let us know how you get on with the suggestion.

    Another thing you can do is to teat for a valid internet connection before running your HTTP request. I always check for a valid internet connection using MLWiFi before sending any request to the internet. You never know, even when connected via WiFi or 4G...
    Last edited: Apr 10, 2015
  3. Erel

    Erel Administrator Staff Member Licensed User

    This is not related to the network on main thread exception. HttpUtils2 handles all of the communication in the background.

    You should expect some http requests to fail. There can be all kinds of reasons for failures. Based on the error it could be a server error.

    Collect the failed requests and try to send them again after a few seconds.
  4. achtrade

    achtrade Active Member Licensed User

    it's handling well the failed request, it's trying again every 7 seconds, just I'm wonder why it's failing too much, I thought that my code had something wrong

    something to do with this : job.GetRequest.Timeout = xxx ?

    I'm using the HTTP lib v. 1.36, is that the right one ?

    I've finally done a beautiful app and now this is happening to me
    Last edited: Apr 10, 2015
  5. Peter Simpson

    Peter Simpson Expert Licensed User

    I had the exact same issue @achtrade, but now it's working. Let us know if you get it working.

    Now it's snooker match time so I've got to go ;)
    Last edited: Apr 11, 2015
    DonManfred likes this.
  6. Erel

    Erel Administrator Staff Member Licensed User

    v1.36 is the latest version.
  7. achtrade

    achtrade Active Member Licensed User

    Ok, I went to the nearest McDonalds and there my app worked well in my two devices only with wifi. The strange thing is that in my office and my home I getting this behavior with the network. I would like to identify what the problem is ..... (scratching my head)
  8. Peter Simpson

    Peter Simpson Expert Licensed User

    Use MLWiFi to test for internet connection before doing anything else. If MLWiFi says there is an internet connection then process your HTTP request, if it says that it's not online then loop back and check again until it says that there is an internet connection.
    DonManfred likes this.
  9. MarcoRome

    MarcoRome Expert Licensed User

    Hi Achtrade, do you have identified the Problem ?
  10. achtrade

    achtrade Active Member Licensed User

    I didn't identify it, the issue persist in a random way, even in a McDonalds, I think that it is a Godaddy problem (my db is there), so, I'm changing everything to RDC with my own server.
    MarcoRome likes this.
  11. MarcoRome

    MarcoRome Expert Licensed User

    Achtrade but in this way do you solved ? you've already done some testing ?
  12. achtrade

    achtrade Active Member Licensed User

    Yes, It solved my problem, I tested it with the RDC sample and I put the same timer as in my app and leave it on for almost an hour, firing the ExecuteQuery every 7 seconds with no error connection.

    Before, my app was getting error after 3 or 5 successful connections.
    MarcoRome likes this.
  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