B4J Question jOkHTTPUtils2 never receiving result

MathiasM

Active Member
Licensed User
Hello

I tried the jOKHTTPUtils2 Wait For demo code from Erel, however, I never seem to get any result, nor any error, how can I identify the proble?

Full code used:
B4X:
'Non-UI application (console / server application)
#Region Project Attributes
    #CommandLineArgs:
    #MergeLibraries: True
#End Region

Sub Process_Globals
    
End Sub

Sub AppStart (Args() As String)
    Dim j As HttpJob
    j.Initialize("", Me)
    j.Download("http://www.google.com")
    Log("Waiting...")
    Wait For (j) JobDone(j As HttpJob)
    If j.Success Then
        Log(j.GetString)
    Else
        Log(j.ErrorMessage)
    End If
    Log("Never reached")
    j.Release
End Sub

'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    Return True
End Sub

Output:

Waiting...

And it stays like this forever. I have a normal internet connection. How can I identify what's going on here?

Thank you
 

OliverA

Expert
Licensed User
Longtime User
You cannot use Wait For in AppStart of a Non-UI app. There is no message loop and therefore the program actually ends at
B4X:
Wait For (j) JobDone(j As HttpJob) ' Think about what this does and then you'll realize why the program stops here (when used in AppStart)
Try
B4X:
'Non-UI application (console / server application)
#Region Project Attributes
    #CommandLineArgs:
    #MergeLibraries: True
#End Region

Sub Process_Globals
    
End Sub

Sub AppStart (Args() As String)
    DownloadPage
    StartMessageLoop ' This will be executed once the Wait For line is reached in DownloadPage
End Sub

Sub DownloadPage
    Dim j As HttpJob
    j.Initialize("", Me)
    j.Download("http://www.google.com")
    Log("Waiting...")
    Wait For (j) JobDone(j As HttpJob) ' This will "stop" DownloadPage and the app will execute the commands below the DownloadPage call in AppStart
    If j.Success Then
        Log(j.GetString)
    Else
        Log(j.ErrorMessage)
    End If
    Log("Never reached") ' It will now
    j.Release
    StopMessageLoop ' Needed to end the applicatoin
End Sub

'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    Return True
End Sub
 
Upvote 0
Top