Android Question org.apache.http.conn.ConnectTimeoutException

Discussion in 'Android Questions' started by danijel, Mar 30, 2015.

  1. danijel

    danijel Member Licensed User

    Hi
    I am trying to download Html page using Httpjob.
    Everything works fine on my 4 test devices except on Htc Desire 601 (KitKat)

    Only on that device sometimes (1 in 10 times approx.) I get this error:
    org.apache.http.conn.ConnectTimeoutException: Connect to /xxx.xxx.xxx.xxx:80 timed out

    P.S. That device is on the same Wi-Fi as my other 4 devices.
    Wi-Fi is working all the time. And Internet works on all devices all the time

    What's causes this error?
    -My device,
    -My code or
    -My remote server

    ...and how to fix this? o_O

    Thank you in advance
     
  2. DonManfred

    DonManfred Expert Licensed User

    Maybe you need to increase the timeouttime

    Code:
    Dim GetWhatever As HttpJob
        GetWhatever.Initialize(
    "GetWhatever", Me)
        GetWhatever.Download... 
    'or whatever
        GetWhatever.GetRequest.Timeout = DateTime.TicksPerSecond * 10 '10 = 10 seconds etc...
     
  3. danijel

    danijel Member Licensed User

    Thx @DonManfred I'll try,
    but.. when it works all is done in less than 1 sec.
    I am not sure that that will help
     
  4. DonManfred

    DonManfred Expert Licensed User

    without seeing your code it is hard to give advices.
    When it all happens withion 1 second than the problem seems to be something other.
    Maybe you are reusing the httpjob instance
    Maybe your Router
    Maybe your Destintion pc (firewall/Antivirus)
     
  5. danijel

    danijel Member Licensed User

    I am using httpjob only once.
    router works fine for other devices and for that device in 90% cases.

    hmm o_O
     
  6. MarcoRome

    MarcoRome Expert Licensed User

    Something
    if you have two or more devices on the same Wi-Fi network and try to connect on MySql ... you have this error.
    Try to connect a device over wi-fi and the other Internet phone and you'll see that you will not have this error.
    I didn't understand why.
    Any idea ??
     
  7. danijel

    danijel Member Licensed User

    Yes, I noticed that too.
    On 3G works fine,
    but sometimes there is an error if more devices is on same Wi-Fi
     
  8. MarcoRome

    MarcoRome Expert Licensed User

    Yes agree somethings for me.
    I have 2 device in Wi-Fi and i have this error.
    If run one device in internet mobile ( 1 device in wi-fi / 1 device in inet mobile ) all work without problem.
    So seem that 2 o more device that work in some Wi-Fi have this error
     
  9. MarcoRome

    MarcoRome Expert Licensed User

    Hi all.
    I have this simple code:
    Code:
    Sub Process_Globals
     
        
    'These global variables will be declared once when the application starts.
           'These variables can be accessed from all modules.
        Dim httpC As HttpClient
        
    Dim httpD As HttpClient
     
        
    Dim GENERE = "genere" As String
        
    ' Inserire Pw e Server e compilare come obfuscated
        Dim ipserver, dbname, dbpw, userdb As String
        
    'richiamo DB MySQL
        ipserver = "xxx.xx.xxx.xxx"
        dbname = 
    "xxxx"
        dbpw = 
    "xxxxx"
        userdb = 
    "xxxx"
       
    End Sub
     
    Sub Globals
        
    Private ListView1 As ListView
    End Sub
     
    Sub Activity_Create(FirstTime As Boolean)         
                    
    Activity.LoadLayout(dispositivo)
                    ExecuteRemoteQuery(
    "SELECT a, b FROM example", GENERE)
    End Sub
     
     
    Sub ExecuteRemoteQuery(Query As String, JobName As String)
        
    Dim job As HttpJob
        job.Initialize(JobName, Me)
        job.PostString(
    "http://www.xxxxx.eu/db.php?hst="&ipserver&"&db="&dbname&"&usr="&userdb&"&pwd="&dbpw&"", Query)
    End Sub
     
     
     
    Sub JobDone(Job As HttpJob)
        
    ProgressDialogHide
        
    If Job.Success Then
        
    Dim res As String
            res = Job.GetString
            
    Log("Response from server: " & res)
            
    Dim parser As JSONParser
            parser.Initialize(res)
            
    Select Job.JobName
     
            
    'Seleziono Esempio
            Case GENERE
                    
    Dim COUNTRIES As List
                    
    Dim m As Map
                    m.Initialize
                    COUNTRIES = parser.NextArray 
    'returns a list with maps
                    For i = 0 To COUNTRIES.Size - 1
                        m = COUNTRIES.Get(i)
                        ListView1.AddTwoLines(m.Get(
    "a"), m.Get("b"))
                    
    Next
            
    End Select
        
    Else
            
    ToastMessageShow("Error: " & Job.ErrorMessage & " Errore connessione Internet, verificare!!"True)
        
    End If
        Job.Release
    End Sub
    Everything works if:
    A) using a single device on the same wi-fi
    B) use multiple devices on different inet (such as a mobile device on inet + 1 device on wi-fi)

    If i try with two devices on the same wi-fi, the first run the code, the second remains on standby, after giving me a few seconds this error:
    org.apache.http.conn.ConnectTimeoutException: Connect to /xxx.xxx.xxx.xxx:80 timed out

    Any ideas?

    thank you
    Marco
     
  10. MarcoRome

    MarcoRome Expert Licensed User

    I have a doubt , while using Job.release , in theory should release resources ( but connection is anyway open ) the service work anyway. If after job.relese add
    StopService(HttpUtils2Service)

    Code:
    Job.Release
    StopService(HttpUtils2Service)
    Contraindications ??
     
  11. Erel

    Erel Administrator Staff Member Licensed User

    You shouldn't stop the service as it will cause multiple http clients to be created.
     
  12. MarcoRome

    MarcoRome Expert Licensed User

    Thank you.
    I think that this problem is widespread.
    Erel do you have solution, suggestion ??

    Thank you
    Marco
     
  13. Erel

    Erel Administrator Staff Member Licensed User

    You should expect download failures and use a timer to retry the download.
     
  14. MarcoRome

    MarcoRome Expert Licensed User

    RESOLVED.
    You can
    1. Use RDC
    2. Use Library MySql DonManfred ... already Tested and work without problem.
     
  15. MarcoRome

    MarcoRome Expert Licensed User

    The problem is ONE: SSL certificate.
    If you add SSL work in multiuser without problem, so the only change your code is this:
    in
    Bye
    Marco
     
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