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:
Thank you Erel.
Marco
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