B4J Tutorial [WebApp] Web Apps Overview

Discussion in 'B4J Tutorials' started by Erel, Apr 10, 2014.

  1. Erel

    Erel Administrator Staff Member Licensed User

    [​IMG]

    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.
     

    Attached Files:

    Last edited: Apr 18, 2014
  2. Toley

    Toley Active Member Licensed User

  3. Erel

    Erel Administrator Staff Member Licensed User

    The web server is online. Maybe your firewall blocks outgoing connections to non-standard ports.
     
  4. Toley

    Toley Active Member Licensed User

    Sorry for the false report, it's probably the firewall at work. At home it works fine.
     
  5. Toley

    Toley Active Member Licensed User

    Another quick question Erel. Is it hosted on your Raspberry Pi ?
     
  6. little3399

    little3399 Active Member Licensed User

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

    SecureRandom ,MessageDigest,
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    No. The online examples are hosted on the site server (linux). Though you can host it on a Raspberry Pi board.

    The libraries are listed at the end of the first post.
     
  8. rwblinn

    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

    [​IMG]

    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.
     
    JCO, pesquera, KingKing and 5 others like this.
  9. Erel

    Erel Administrator Staff Member Licensed User

    Great work!

    Can you also post it in the share your creations or as a new tutorial (otherwise it will be more difficult to find)?
     
  10. rwblinn

    rwblinn Well-Known Member Licensed User

    Hi Erel,

    thanks a lot - Have posted as a new tutorial.
     
    Kwame Twum and Erel like this.
  11. Erel

    Erel Administrator Staff Member Licensed User

    ServerExampleNoMySQL project was uploaded to the first post. This project doesn't depend on a MySQL database and is easier to start with.
     
  12. rwblinn

    rwblinn Well-Known Member Licensed User

    Hi,

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

    Erel Administrator Staff Member Licensed User

    This is a new method, not included in the beta. I will soon release v2.00.
     
  14. swissmade

    swissmade Active Member Licensed User

    Just in time to get this version.
    Need to build some web applications.

    Many thanks Erel
     
  15. little3399

    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 ?
     
  16. Erel

    Erel Administrator Staff Member Licensed User

    The compiled jar is a web server itself. Jetty is embedded inside.
    You just need to run it by double clicking on the jar or with java -jar <yourjar>
     
    pesquera and Theera like this.
  17. DonManfred

    DonManfred Expert 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
     
  18. little3399

    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 ?
     
  19. Erel

    Erel Administrator Staff Member 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.

    The performance should be very good. See some numbers here: [Server] Performance measures
     
  20. DonManfred

    DonManfred Expert Licensed User

    "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
     
Loading...