Android Question [SOLVED] org.apache.http.conn.ConnectTimeoutException

MarcoRome

Expert
Licensed User
Longtime User
As required by Erel i open this new thread.
Already time ago we talked about THIS

The problem is okHttp in same WiFi:
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

This is simple code:
B4X:
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

Thank you Erel.
Marco
 

MarcoRome

Expert
Licensed User
Longtime User
To find the problematic point, try it with this code:
B4X:
Sub Activity_Click
   Dim j As HttpJob
   j.Initialize("j", Me)
   j.Download("https://www.b4x.com/print.php?a=d")
End Sub
Sub JobDone(j As HttpJob)
   ToastMessageShow($"Success = ${j.Success}"$, True)
   j.Release
End Sub
Give me Success = True
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
This means that the problem is in your server. There is probably some DDOS protection or QOS service running that prevents multiple calls from the same ip address. It has nothing to do with OkHttp.
mmh... i got it. But why MSsql By Don Manfred work ?
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
Hi Erel, they said that there is no lock for DDOS protection or QOS service running that prevents multiple calls from the same ip address.
Another idea ?
Thanks
Marco
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
Which Provider do you have and which product? Maybe it is good for 1 connection at a time only....
Hi KMatle, unfortunately isnt so. I utilize xlogic.org is good provider and i never had problems. About this provider i have site and DB. All connection ( also multiple ) work if "direct"without problem. Most likely is as says Erel ( DDOS protection or QOS service running that prevents multiple calls from the same ip address ) also if i open ticket with this question and answer is that they havent this.
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
To find the problematic point, try it with this code:
B4X:
Sub Activity_Click
   Dim j As HttpJob
   j.Initialize("j", Me)
   j.Download("https://www.b4x.com/print.php?a=d")
End Sub
Sub JobDone(j As HttpJob)
   ToastMessageShow($"Success = ${j.Success}"$, True)
   j.Release
End Sub
Erel pls can you send me print.php so i try upload in my server ?
Thank you
Marco
 
Upvote 0
Top