B4J Question OkHttpUtils2 issue with Non-UI app

magarcan

Active Member
Licensed User
Longtime User
Here is the code:
B4X:
        Dim j As HttpJob
        j.Initialize("", Me)
        j.Download("https://www.google.com")
        Wait For (j) JobDone(j As HttpJob)
        If j.Success Then
            Log(j.GetString)
        End If
        j.Release

Same code runs without any problem within B4XPages but itdoesn't using Console (Non-UI).

Does it makes any sense?
 

DonManfred

Expert
Licensed User
Longtime User
 
Upvote 0

magarcan

Active Member
Licensed User
Longtime User
Thank you for the anser, but as I understood
A handler is a B4J class that is mapped to a URL. A handler class is responsible for getting the request and providing the response.

The fact is that I'm not working as a server, just a little console program without GUI.
 
Upvote 0

magarcan

Active Member
Licensed User
Longtime User
B4X:
Sub AppStart (Args() As String)
    Dim tr As TextReader
    tr.Initialize(File.OpenInput(File.DirApp, Args(0)))
        
    Dim line As String
    line = tr.ReadLine

    Do While line <> Null
        line = tr.ReadLine
            
        Dim j As HttpJob
        j.Initialize("j", Me)
        j.Download(line)
        Log("Downloading: " & line)
        StartMessageLoop
    Loop
    tr.Close
    ExitApplication2(0)   
End Sub

B4X:
Sub JobDone(Job As HttpJob)
    If Job.Success Then
        Log(Job.GetString)
        Log("ENDDDDDDDDDDDD")
        '...
    Else
        Log(Job.ErrorMessage)
    End If
    Job.Release
    StopMessageLoop
End Sub

But I get an error just before download second file:
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Two "code smells" ( [B4X] "Code Smells" - common mistakes and other tips ):
1. JobDone sub.
2. TextReader.

B4X:
Sub AppStart (Args() As String)
  Download
  StartMessageLoop
End Sub

Sub Download
 Dim lines As List = File.ReadList(...)
 For Each line As String In lines
       Dim j As HttpJob
        j.Initialize("", Me)
        j.Download(line)
        Wait For (j) JobDone (j As HttpJob)
         If j.Success Then
             ...
         End If
         j.Release
 Next
 ExitApplication
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…