B4J Tutorial [WebApp] Web Apps Overview

Status
Not open for further replies.

Erel

Administrator
Staff member
Licensed User


B4J v2.00 adds support for web applications based on WebSocket technology. With WebSocket The browser and the server maintain an open communication channel.
This channel allows us to build web apps where all (or most) of the logic is implemented in the server.

The new framework is implemented in jServer library. It adds a new type of "handler" named WebSocket.
The browser UI is implemented in html / css.

B4J Web App Goals
  • Simple to build real-world web applications with the same libraries and similar code as done in B4J / B4A.
  • Good performance.
  • Very easy to extend.
You can see several online examples here: http://basic4ppc.com:51042/

The source code of all these examples is attached to this post.

What you need to know?
  • Server library tutorial: [Server] Building web servers with B4J
    This tutorial was written before WebSockets were available.
  • Html / CSS - Required for the UI.
  • (recommended) Basic knowledge of jQuery. JQuery is a JavaScript library that simplifies access to html elements. B4J WebSocket client side implementation is based on jQuery.
Which browsers are supported?

All modern browsers support web sockets. See this table: http://caniuse.com/websockets
Android is a bit late here. The Chrome browser (compatible with Android 4.0+) supports web sockets.

How to deploy?

The compiled jar file is a standard Java app. The web server is embedded in this jar.
Any computer with Java 7+ installed can run it (including boards such as Raspberry Pi).
Shared hosting solutions will not work as they don't support Java. VPS solutions will work.
You can also turn a local computer into a public web server with a dynamic dns service:
http://www.basic4ppc.com/android/fo...r-b4j-server-over-the-internet.37201/#content
Tip: if you are running it in linux then you should use the nohup command.

Where do I go from here?

[WebApp] Hello World Web App
Other tutorials: http://www.basic4ppc.com/android/forum/pages/results/?query=webapp&page=1&prefix=18

The online examples project is attached.
The full project depends on a MySQL database (and several other libraries - see post #19).
You can start with the NoMySQL project which doesn't depend on MySQL.
 

Attachments

Last edited:

Toley

Active Member
Licensed User
Sorry for the false report, it's probably the firewall at work. At home it works fine.
 

little3399

Active Member
Licensed User
Where can I found the Lib for download ? which in the Onlineexample.zip .... Tks!

SecureRandom ,MessageDigest,
 

rwblinn

Well-Known Member
Licensed User
Hi All,

find attached my first B4J WebApp, a simple TaskMgr, based upon B4J v2.00 and WebSockets.
It is amaizing what can be done with this new technology - a lot to learn & explore!
Thanks a lot to Erel for the further development of B4J - such a great product!

Download TaskMgr: http://www.rwblinn.de/b4j/b4jhowto/examples/b4jhowtowebapptaskmgr.zip



Notes:
  • when clicking on Date, a DatePicker is shown based upon jQuery UI datepicker.
  • to learn more about jQuery, this sample app will be developed further.
 

rwblinn

Well-Known Member
Licensed User
Hi,

when compiling receive an error message:
Unknown member: debugnetworklatency. Occurred on line: 54
srvr.DebugNetworkLatency = 200
 

swissmade

Well-Known Member
Licensed User
Just in time to get this version.
Need to build some web applications.

Many thanks Erel
 

little3399

Active Member
Licensed User
Hi, Erel

The B4J compiled jar file can be as a webapp app and put it into the web server , such as Jetty,Tomcat ... etc ?
 

little3399

Active Member
Licensed User
Hi, Erel

How about the Performance of the compiled jar apps that embedded web server ? Maybe I feel it running slow ?

Whether it is suitable for a production environment ?
 

Erel

Administrator
Staff member
Licensed User
where do i find all the needed libraries for the examples?

It would be great if you can set links to the needed libraries in first post.

Actually i´m searching for (and did not find them actually):
SecureRandom, MessageDigest, ByteConverter
I recommend you to start with the ServerExampleNoMySQL project. It only depends on "core" libraries.

The full project depends on: jExcel, ByteConverter and Encryption library (last two are B4A libraries).
It also depends on the MySQL jdbc driver.

How about the Performance of the compiled jar apps that embedded web server ? Maybe I feel it running slow ?

Whether it is suitable for a production environment ?
The performance should be very good. See some numbers here: [Server] Performance measures
 

DonManfred

Expert
Licensed User
I recommend you to start with the ServerExampleNoMySQL project. It only depends on "core" libraries.

The full project depends on: jExcel, ByteConverter and Encryption library (last two are B4A libraries).
It also depends on the MySQL jdbc driver.
"last two are B4A libraries"; THAT´s what i have missed. I search the b4j-libraries forum from top to bottom and back to top and back to bottom but i cant find them. Sure; i was searching the wrong place :-/

Thank you... I´ll start again at this today
 
Status
Not open for further replies.
Top