B4J Tutorial [WebApp] Web Apps Overview

Status
Not open for further replies.
SS-2014-04-10_17.09.21.png


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:
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 8+ 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.b4x.com/android/forum/th...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.b4x.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.

The full project depends on: jBuilderUtils, jExcel, ByteConverter and Encryption.

Updates

- b4j_ws.js v0.92 is included in the zips. It fixes a potential issue where events are registered multiple times.
 

Attachments

  • ServerExample.zip
    75.1 KB · Views: 1,664
  • ServerExampleNoMySQL.zip
    71.8 KB · Views: 1,700
Last edited:

Toley

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

Toley

Active Member
Licensed User
Longtime User
Another quick question Erel. Is it hosted on your Raspberry Pi ?
 

little3399

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

SecureRandom ,MessageDigest,
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Is it hosted on your Raspberry Pi ?
No. The online examples are hosted on the site server (linux). Though you can host it on a Raspberry Pi board.

Where can I found the Lib for download ? which in the Onlineexample.zip
The libraries are listed at the end of the first post.
 
  • Like
Reactions: wvg

rwblinn

Well-Known Member
Licensed User
Longtime 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
Longtime User
Hi,

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

Swissmade

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

Many thanks Erel
 

little3399

Active Member
Licensed User
Longtime 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 ?
 

DonManfred

Expert
Licensed User
Longtime 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
 

little3399

Active Member
Licensed User
Longtime 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

B4X founder
Staff member
Licensed User
Longtime 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: jBuilderUtils, jExcel, ByteConverter and Encryption.
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
 
Last edited:

DonManfred

Expert
Licensed User
Longtime 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