B4J Tutorial [server] Http/2 Configuration

Discussion in 'B4J Tutorials' started by Erel, Dec 16, 2015.

  1. Erel

    Erel Administrator Staff Member Licensed User

    New tutorial: https://www.b4x.com/android/forum/threads/server-conscrypt-and-http-2.93040/

    B4J v4.00 adds support for Http/2. This is the new version of the Http protocol.

    The two main benefits:
    1. Better performance with less server overhead.
    2. Optional protocol. If the browser doesn't support it then Http 1.1 will be used instead.

    Note that all modern browsers support Http/2.

    Adding support for Http/2 requires some configuration:
    1. Configure SSL as it only works with SSL (https) connections: [Server] SSL Connections
    2. Set Server.Http2Enabled to True.
    3. Add the alpn boot jar to the boot class path.
    You need to download and add a jar file named alpn-boot.
    You can read more about this jar file (including its license) here: http://www.eclipse.org/jetty/documentation/current/alpn-chapter.html

    You need to download the correct version based on the Java version.
    The jars are available here: http://search.maven.org/#search|gav|1|g:"org.mortbay.jetty.alpn" AND a:"alpn-boot"

    For Java 8.65 and 8.66 you can download this jar: http://search.maven.org/remoteconte...8.1.6.v20151105/alpn-boot-8.1.6.v20151105.jar

    The jar file should be copied to the Objects folder.

    During development you need to use the #VirtualMachineArgs attribute to add this jar to the classpath:
    #VirtualMachineArgs: -Xbootclasspath/p:alpn-boot-8.1.xxxxxxx.jar
    Command line / terminal:
    java -Xbootclasspath/p:alpn-boot-8.1.4.v20150727.jar -jar <your jar>.jar
    An example is attached. You will need to update the alpn version based on your Java version and run it.

    It will display the protocol used. Try it with these two links: (should display Http/1.1) (should display Http/2)

    The second one will issue a warning about the unrecognized certificate, as this is a self signed certificate.

    Attached Files:

    Last edited: May 15, 2018
  2. dar2o3

    dar2o3 Active Member Licensed User

    I have a problem with this.
    When I run the server is operating properly, start the first session without problems when I try to access another computer with a different user can not, the first session is working properly but the second remains as frozen.
    Anyone have any idea?

    my version of Java is: 1.8.0-b132

    my version alpn is : alpn-boot-8.1.1.v20141016.jar
  3. dar2o3

    dar2o3 Active Member Licensed User

    The problem, I think it has to do with the version of Java installed on my raspberri pi 2, Windows works perfect, the version of Java on Windows is 1.8.0_71-b15
  4. dar2o3

    dar2o3 Active Member Licensed User

    updated version of java the problem disappeared.
  5. mrred128

    mrred128 Active Member Licensed User

    It works like a charm on my win10 machine, run from the ide. On the odroid XU4 (RasberryPI on steroids) it works for about 15 mins and then goes deaf. Ubuntu 14.04lts and Oracle/Sun jvm 8.8.0_77-b03 (32 bit) alpn-boot-8.1.7.v20160121.jar. The alpn-boot-8.1.6.v20151105.jar didn't work at all on the odroid. The odroid generally is in continuous operation in the http/1 mode with no issues.
  6. Erel

    Erel Administrator Staff Member Licensed User

    Are you monitoring the logs? Are there any errors?

    If not then there is nothing that you can do expect of use Http/1.
  7. mrred128

    mrred128 Active Member Licensed User

    Nothing special, I just posted as a FYI. For what I need it to do, standard implementation works like a charm. I haven't looked that deeply, but there may even be some native code in there that may/may not be implemented. Every arm processor seems to be slightly different.
  8. mrred128

    mrred128 Active Member Licensed User

    After I posted this, it started to bug me as to why. It turns out that my jason servelts and dynamic content publisher used more threads and thus more connection pool items. It was choking. I increased the connection pool size and it lives. Why not Windows vs the Linux/ARM I have no idea.
  9. MarkG

    MarkG New Member

    Looks interesting. Sorry for asking, but would this be painful to port to B4A?
  10. Erel

    Erel Administrator Staff Member Licensed User

    This solution is relevant for http servers. It is less relevant to B4A.

    OkHttp does support Http/2 as a client.
  11. stanmiller

    stanmiller Active Member Licensed User

    Which java version did you update? The Java runtime on the raspberry? The runtime of your Windows or the JDK on Windows?
  12. dar2o3

    dar2o3 Active Member Licensed User

    The java versión on the raspberry
  13. stanmiller

    stanmiller Active Member Licensed User

    Thanks for the reply.

    I was having a ALPN not configured exception on a VPS running Unbuntu. I upgraded my JDK to match the runtime installed on the server. Plus I had to put the alpn-boot-8.1.xxxxxxx.jar in the same folder as my app.jar on the server.

    Works now.
    Last edited: Sep 13, 2016
    magi6162 and dar2o3 like this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice