B4J Tutorial [server] Http/2 Configuration

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.
http://www.eclipse.org/jetty/documentation/current/alpn-chapter.html#alpn-versions
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:
B4X:
#VirtualMachineArgs: -Xbootclasspath/p:alpn-boot-8.1.xxxxxxx.jar

Command line / terminal:
B4X:
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:
http://127.0.0.1:51041/test (should display Http/1.1)
https://127.0.0.1:51042/test (should display Http/2)

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

Attachments

  • Http2.zip
    1.3 KB · Views: 1,114
Last edited:

dar2o3

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

dar2o3

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

mrred128

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

mrred128

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

mrred128

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

stanmiller

Active Member
Licensed User
Longtime User
The java versión on the raspberry

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:
Top