B4J Question Stop a running server

joseluis

Active Member
Licensed User
Longtime User
So I'm making a library wrapping a Google REST API.

And the way I'm doing the OAUTH2 authorization is by starting a local server, opening the login website for the user to login and receiving the response in the local server. After that I don't really need the local server anymore.

Is there a way to stop it? maybe having the code in a class, and destroying the instance after using it somehow?

Or, are there any disadvantages for leaving it running all the time? (apart from having an unnecessary port opened)
 

joseluis

Active Member
Licensed User
Longtime User
Thank you, I didn't see that thread.

I will have to make some tests because I don't know what the effects of calling ExitApplication will be, specially when this will be compiled to a library. Will it exit the application that is using my library?
 
Upvote 0

joseluis

Active Member
Licensed User
Longtime User
I'm using jServer since I don't know any other way. Could it be done using a more low level approach, enabling to stop it maybe?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can stop a server with JavaObject:
B4X:
Dim jo As JavaObject = server
jo.GetFieldJO("server").RunMethod("stop", null)

Note that it may be problematic to embed the server handlers in a library. It will not work for a UI app.

It will be simpler to create a small "server" app and start it with jShell (see B4J-Bridge on how to do it). You can print the required data to the console and exit. This will allow you to read the result from the other app.
 
Upvote 0
Top