B4J Question How to create a server application width B4J

Roberto P.

Well-Known Member
Licensed User
Longtime User
hello to the comunity,

I ask for help B4J:

- I need to create an application installed on the server and visible from the outside with a public IP and port, which remains in "listen" for requests from clients Android.
In practice, this application written with B4J is running on the server available to clients asking for Android to communicate and exchange files.
can you help me with an example?

thanks to anyone who can help me
Roberto P.
 

dilettante

Active Member
Licensed User
Longtime User
I'm not sure it is possible yet.

First you have to pick a platform. Let's say Windows.

Then it seems as if you have to use a wrapper program that runs your JAR file (see How do I run a java .jar file as a windows service on windows server 2008? though I couldn't tell you how authoritative the info there is).

And your JAR file (B4J) program has to be GUI-less, i.e. a command line program. I'm not sure what the impact of this is, but I'm not convinced that B4J async operations, events, etc. work with no GUI.

... and there may be other details involved.

Hopefully somebody else can provide more specifics. I had the idea however that this was going to have to wait for a new B4J project type.
 
Upvote 0

Roberto P.

Well-Known Member
Licensed User
Longtime User
I am sure that it is possible to make this application! it comes to understanding how to do it with this development environment. the application, which could also have a GUI, must wait for the connection of clients that can request access to share data and files.
Being a Java application, it can be performed on any server, but not windows.
I hope I have made clear.
regards
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
Yes b4j currently lacks the HttpServer library.
Erel says he plans a more comprehensive server library for b4j so hasn't implemented HttpServer.
I wish he'd add HttpServer now and when he has time implements more advanced features.
But for now b4j has no HttpServer support :-(.

Martin.
 
Upvote 0

Roberto P.

Well-Known Member
Licensed User
Longtime User
ho visto che c'è l'oggetto ServerSocket e che dovrebbe essere adatto a fare la connessione con i clients.
si tratta di capire come gestire la connessione in attesa di accesso dai clientes.
 
Upvote 0

dilettante

Active Member
Licensed User
Longtime User
I am sure that it is possible to make this application! it comes to understanding how to do it with this development environment. the application, which could also have a GUI, must wait for the connection of clients that can request access to share data and files.
Being a Java application, it can be performed on any server, but not windows.
I hope I have made clear.
regards

If you need it to run on a server machine it needs to run as a service/daemon. This means it can't have a GUI... except as a separate admin application.

I don't think the HttpServer library has anything at all to do with this except for the degenerate case where you want the service to be an HTTP service.

If all you want is a basic example of how to write a B4J program that can be a socket server see Simple Multi-User Chat Demo. However it has the same problem: it is not a service/daemon but a GUI application that must be kept running by a logged on user.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Yes b4j currently lacks the HttpServer library.
Erel says he plans a more comprehensive server library for b4j so hasn't implemented HttpServer.
I wish he'd add HttpServer now and when he has time implements more advanced features.
But for now b4j has no HttpServer support :-(.

Martin.
This is correct. Support for "web server" apps will hopefully be available in a few weeks.

I don't think the HttpServer library has anything at all to do with this except for the degenerate case where you want the service to be an HTTP service.
It is true that you can already create a raw server using sockets. However it will be much simpler, powerful and reliable to build a real web server.

it is not a service/daemon but a GUI application that must be kept running by a logged on user.
This is not correct. Any app can run in the background (and can be scheduled to start after boot). You do not need a GUI for that.

If you like you can convert the Java app to a windows executable and then convert it to a standard service.
 
Upvote 0

Roberto P.

Well-Known Member
Licensed User
Longtime User
I also think it would be better a web application, but since you can not do it with B4J, should you do with the socket.
Now that it is clear what to do, which I believe is useful to many other programmers who want to create an effective system for exchanging data between Android devices and business applications, you have an example of an application that is launched and listens for connections?
I have the code to Java, but I prefer to do it with B4J.
thank you very much
 
Upvote 0

stefanogoria

Member
Licensed User
Longtime User
I also think it would be better a web application, but since you can not do it with B4J, should you do with the socket.
Now that it is clear what to do, which I believe is useful to many other programmers who want to create an effective system for exchanging data between Android devices and business applications, you have an example of an application that is launched and listens for connections?
I have the code to Java, but I prefer to do it with B4J.
thank you very much
Hi Roberto, I understand what have to plan to do.
I think ServerSochet is the best way but there could be some problems:
1) you have to manage port on your server (firewall etc.etc.)
2) you have to manage a parser for command you will receive
3) I have realized an application to test your same idea in B4A and works fine
4) perchè continuiamo a parlare in inglese ? ;)
 
Upvote 0

Roberto P.

Well-Known Member
Licensed User
Longtime User
Ciao Stefano,
è un piacere parlare nella nostra madre lingua, anche perchè l'inglese delle nostre scuole non è proprio il massimo!
comprendo e condivido i punti che dici. La questione è quella di avere gli strumenti e le modalità per poter realizzare il sistema di scambio dati fra le applicazioni mobile e gestionali che credo ci coinvolga tutti.
Ti sono grato se vorrai e potrai condividere con me la tua esperienza.
grazie in anticipo.
roberto
 
Upvote 0

Jmu5667

Well-Known Member
Licensed User
Longtime User
Hi Guys

Has there been an update on this. We need to develop a B4J server that will accept multiple connections, keep them open. I would like each client connection to run in it own thread. The client app will be a b4a app that will send packets of data to the b4J server app. The B4J server app will then forward that data into another windows server app (our back office solution).

Any advice would be appreciated. If this works well for us we would plan to migrate all of existing tech over to b4J ;)

Regards

John.

p.s

We prefer to work with raw sockets:D
 
Upvote 0
Top