Android Question Problems connecting to Server

David Elkington

Active Member
Licensed User
Longtime User
Hi All,

I am having trouble with my (b4x) Android app and was wondering if anyone had any ideas. I am getting data from an rdc server, and it seems to be able to post data (using a sql insert) but I cannot retrieve any data at all. I am using the following code, which works fine on the iOS app, which is suggesting it is an issue due to Android. I am just getting time outs...

ResponseError. Reason: java.net.SocketTimeoutException: failed to connect to /86.188.234.231 (port 17179) from /192.168.0.132 (port 34312) after 30000ms, Response:

GetVerifyCode:
Sub GetVerifyCode (stremail As String)
   Dim req As DBRequestmanager = CreateRequest
   Dim cmd2 As DBCommand = CreateCommand("select_and_wa_verify_code_34567", Array("1"))
'Dim cmd1 As DBCommand = CreateCommand("select_and_wa_verify_code_34567", Array(stremail))
   Dim j As HttpJob = CreateRequest.Executebatch(Array(cmd2), Null)
    j.GetRequest.Timeout=60000
   Wait For (req.ExecuteQuery(cmd2, 0, "UserInfo")) JobDone(j As HttpJob)
   If j.Success Then
       req.HandleJobAsync(j, "req")
       Wait For (req) req_Result(res As DBResult)
               For myrows = 0 To res.Rows.Size - 1
                Dim Record() As Object = res.Rows.Get(myrows)
               
                pub_ID = Record(0)
                pub_email = Record(1)
                pub_verify_code  = Record(2)
                pub_create_date  = Record(3)
                pub_first_name  = Record(4)
                pub_last_name  = Record(5)
                pub_tree_count  = Record(6)
                pub_water_count  = Record(7)
                pub_remind_me  = Record(8)
                pub_first_scan  = Record(9)
                pub_last_scan  = Record(10)
                pub_verified = Record(11)
                pub_push_token = Record(12)
                lngCorrectCode = pub_verify_code
               
            Next
       'req.PrintTable(res)
   Else ....
 

David Elkington

Active Member
Licensed User
Longtime User
Note, I tried changing the query to use a known value just in cast it was having issues retrieving from a string
Oh, and it can connect to the test url from chrome on the device
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
ExecuteBatch is to run a batch of update or delete commands. It does not return anything. i guess

B4X:
  Dim cmdList as List
   cmdList.Initialize
   For Each Name as String in Names
      Dim cmd as DBCommand = CreateCommand("insert_animal", Array(Name, Null))
      cmdList.Add(cmd)
   Next
   Dim j As HttpJob = CreateRequest.ExecuteBatch(cmdList, Null)
   Wait For(j) JobDone(j As HttpJob)
   If j.Success Then
       Log("Inserted successfully!")
   End If
   j.Release
End
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
Line 4 to 6 are not required.

B4X:
Sub GetVerifyCode (stremail As String)
   Dim req As DBRequestmanager = CreateRequest
   Dim cmd2 As DBCommand = CreateCommand("select_and_wa_verify_code_34567", Array(stremail))
   Wait For (req.ExecuteQuery(cmd2, 0, "UserInfo")) JobDone(j As HttpJob)
 
Upvote 0

David Elkington

Active Member
Licensed User
Longtime User
Thank you for your responses, I will adjust my code, I think I could not see the wood for the trees, I am just trying to get a dataset back, not execute a batch... Will let you know when I have tried.
 
Upvote 0

David Elkington

Active Member
Licensed User
Longtime User
I am still getting the timeout. I dont have another device but other people have said it gives an error on other devices.

It is odd that the port on the device keeps changing, is that normal?
 

Attachments

  • Image 15-02-2024 at 15.37.jpeg
    Image 15-02-2024 at 15.37.jpeg
    96 KB · Views: 76
Upvote 0

David Elkington

Active Member
Licensed User
Longtime User
If I browse from Chrome on the device to the test address, it shows the server is running. However, now I seem to connect once in 50 tries with the code if I keep clicking on my button. I am wondering if my isp is blocking some ports?
 
Upvote 0

josejad

Expert
Licensed User
Longtime User
Verify your server logs (firewall, http, etc...)
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
It is odd that the port on the device keeps changing, is that normal?
Yes. Since jRDC2 communication is based on top of HTTP(s) and HTTP is a stateless protocol, each connection to the server is a new connection and, on many operating systems, the OS gives you the next available port (the +2 increment is not unusual neither).
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
esponseError. Reason: java.net.SocketTimeoutException: failed to connect to /86.188.234.231
You are not showing your code for CreateRequest and the corresponding URL that you pass the req.initialize in that sub. Attaching a barebones app used to test your connection and everything seems to work just fine. If, on the other hand, things seem to work randomly (off and on) then something strange is going on with either the box that hosts the jRDC2 server or the connection leading to that box.

Note: I was lazy and only created a B4J app (even if it's in B4XPages form)
 

Attachments

  • 20240215_jrdc2test.zip
    11 KB · Views: 60
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Note: I was lazy and only created a B4J app (even if it's in B4XPages form)
Rectified. No connection issues under B4A

Note: Please note that the Manifest has an entry that allows non-HTTPS connections for Android (necessary as of API 28)
 

Attachments

  • 20240215_jrdc2test_b4a_b4j.zip
    16.6 KB · Views: 83
Upvote 0
Top