B4J Question JServer - HttpJob working as expected in a desktop app (not needing StartMessageLoop) - I am totally confused

hatzisn

Expert
Licensed User
Longtime User
Good afternoon to all of you,

I am totally confused. I have created a Class in a JettyServer application that makes requests to an on line REST API. I used this code:

B4X:
    Dim sURL As String = "https://myapi.com/v2/setvalue"
    Log(sURL)
    hj.PostString(sURL, sRequestJSON)
    hj.GetRequest.SetHeader("Authorization", sBearer)
    hj.GetRequest.SetContentType("application/json")
 
    Log("-2-")
 
    wait for (hj) JobDone (hj As HttpJob)
 
    Log($"Status Check ${hj.Response.StatusCode}"$)
    sResp = ""

The problem is it works perfect. Then I noticed that I did not need the StartMessageLoop and StopMessageLoop in response. The class is called from a WebSockets class. Is it normal behaviour or I have done something strange? The code is executed on a button click.
 

hatzisn

Expert
Licensed User
Longtime User
jServer shouldn't be used in a UI app. Bad things will happen.
No, I do not use jServer in a UI app. What I said is that the HttpJob with "wait for" worked as it was supposed to work in a UI app. I was confused because normally I would use StartMessageLoop and StopMessageLoop. @EnriqueGonzalez has made clear to me that in a web socket we can use the HttpJob with wait for (hj) JobDone(hj as HttpJob) without the need of StartMessageLoop, StopMessageLoop.
 
Last edited:
Upvote 0

aeric

Expert
Licensed User
Longtime User
No, I do not use jServer in a UI app. What I said is that the HttpJob with "wait for" worked as it was supposed to work in a UI app. I was confused because normally I would use StartMessageLoop and StopMessageLoop. @EnriqueGonzalez has made clear to me that in a web socket we can use the HttpJob with wait for (hj) JobDone(hj as HttpJob) without the need of StartMessageLoop, StopMessageLoop.
Maybe try to understand the concept of server vs client and non-UI vs UI app.

What I understand is Server should always listening to incoming data.

For client app, it usually waiting for user input or events such as click or timer.

I usually see non-UI app uses StartMessageLoop not in UI app.

As for Wait For, I think it is used in both UI and non-UI.
 
Upvote 0

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
Maybe try to understand the concept of server vs client and non-UI vs UI app.
the main idea is that handlers in the server won't wait until the http job finishes, this behavour happens too with non ui apps in the main module because UI apps have an "event loop" integrated.
 
Upvote 0
Top