Android Question ResponseError. Reason: java.net.SocketTimeoutException: timeout, Response:

When ever I get the error
ResponseError. Reason: java.net.SocketTimeoutException: timeout, Response:

Subsequent Connections to using HttpJob don't work on the andriod phone am using to debug the my app
... It will only start to work after I restart the android phone.

Why is that?

Funny thing is it affects all other apps I've designed with B4A making the same request with HttpJob
 
Last edited:
Okay. So this is how the problem occurs..

When I start my application, it loads the splash screen and heads on to my login screen loaded as root of B4XMainpage
B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    fa.Initialize
    Root = Root1
    Wait For (ShowSplashScreen) Complete (Unused As Boolean)
    B4XPages.AddPage("pos_lite_main",pos_lite_main.Initialize)
    B4XPages.GetManager.LogEvents = True
    Root.LoadLayout("login")
 
    submit.Typeface = fa.FontAwesomeTypeface
    submit.Text =  fa.GetFontAwesomeIconByname("fa-user") & " Login"
 
    listlist.Initialize
    select_business_name.SetItems(listlist)

 If File.Exists(File.DirRootExternal,"string.txt") Then
        username.Text = File.ReadString(File.DirRootExternal, "String.txt")
    End If
 
    If File.Exists(File.DirRootExternal,"string2.txt") Then
        select_business_name.text = File.ReadString(File.DirRootExternal, "String2.txt")
    End If
End Sub

Then when there is a successful login it loads this -- I use an API which executes SQL commands and bring back results as JSON. The API url is stored with a process_global variable at application main and I call it to other classes

B4X:
Private Sub submit_Click
    ProgressDialogShow2("Please Wait, Loading",False)
    Dim results_database As String
    Dim job As HttpJob
    job.Initialize("", Me)

'I check if database exist first before I authenticate login credentials

    job.PostString(Main.apilocationURL, "command= SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = 'mcdinosg_" & select_business_name.text & "' & database= mcdinosg_postest")
 
    wait for (job) JobDone(job As HttpJob)
 
    If job.Success Then
        Dim parser As JSONParser
        parser.Initialize(job.GetString)
             
        If job.GetString = "[]" Then
            ProgressDialogHide
            'Msgbox("Username and password not exist","User not found")
        Else
                 
            Dim m As Map
            Dim list1 As List = parser.NextArray
            m = list1.get(0)
         
            results_database = m.Get("SCHEMA_NAME")
         
            ProgressDialogHide
        End If
    End If
    job.Release
 
 
    ' This execute if database exist
    If results_database = "mcdinosg_"& select_business_name.text  Then
        Dim job3 As HttpJob
        job3.Initialize("", Me)
        job3.PostString(Main.apilocation, "command= select username,password,role from login_table where username ='"& username.text &"' and password = '"& password.Text &"' & database= mcdinosg_"& select_business_name.text & "")
 
        Wait For (job3) JobDone(j As HttpJob)
 
        If j.Success = True Then
            Dim parser As JSONParser
            parser.Initialize(j.GetString)
            If j.GetString = "[]" Then
                MsgboxAsync("Username and password not exist","User not found")
            Else
                 
                Dim m As Map
                Dim list1 As List = parser.NextArray
                m = list1.get(0)
                Dim username_ As String = m.Get("username")
                Dim password_ As String = m.Get("password")
                Dim role_ As String = m.Get("role")
            End If
         
            If username_ = "" Or password_ = "" Then
                ProgressDialogHide
            Else
                 
                If username_ = username.text And password_ = password.text Then
                    ProgressDialogHide
                    username.text = ""
                    password.Text=""
                    CallSub3(pos_lite_main, "getname", username_,role_)
'                        StartActivity(Activity2)
'                        Activity.Finish
                    If File.ExternalWritable = False Then
                    Else
                        File.WriteString(File.DirRootExternal, "String.txt",username_)
                        File.WriteString(File.DirRootExternal, "String2.txt",select_business_name.text)
                    End If
                    Try
                        database = "mcdinosg_"& select_business_name.text
'This is where I load the main screen
                        B4XPages.ShowPage("pos_lite_main")
                     
                    Catch
                        Log(LastException)
                    End Try
                     
                Else
                    ProgressDialogHide
                    MsgboxAsync("Username and password not exist","User not found")
                End If
            End If
        Else
            ProgressDialogHide
            Log("Error: " & j.ErrorMessage)
            ToastMessageShow("Error: " & j.ErrorMessage, True)
        End If
        j.Release
    Else
        ProgressDialogHide
        MsgboxAsync("Business name not exist","")
    End If
 
End Sub


After Login when I show
B4XPages.ShowPage("pos_lite_main")

And click the back arrow, it takes me to login screen.
When I try login again, that is when the error start.

Even if I stop debugging and start again, http jobs don't get executed unless I restart the phone I'm using for debugging.

this is the error from second login
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
** Activity (activity2) Create, isFirst = true **
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
** Activity (activity2) Resume **
*** Service (httputils2service) Create ***
*** mainpage: B4XPage_Disappear [mainpage]
*** pos_lite_main: B4XPage_Appear [mainpage]
*** mainpage: B4XPage_Disappear [mainpage]
*** pos_lite_main: B4XPage_Appear [mainpage]
*** mainpage: B4XPage_Disappear [mainpage]
*** pos_lite_main: B4XPage_Appear [mainpage]
*** mainpage: B4XPage_Disappear [mainpage]
*** pos_lite_main: B4XPage_Appear [mainpage]
*** pos_lite_main: B4XPage_CloseRequest [mainpage, pos_lite_main]
-1
*** pos_lite_main: B4XPage_Disappear [mainpage, pos_lite_main]
*** mainpage: B4XPage_Appear [mainpage, pos_lite_main]
ResponseError. Reason: java.net.SocketTimeoutException: timeout, Response:
Error: java.net.SocketTimeoutException: timeout
ResponseError. Reason: java.net.SocketTimeoutException: timeout, Response:
 
Upvote 0
Top