Other Http 2.0 is coming...

Erel

B4X founder
Staff member
Licensed User
Longtime User
Http/2 is the next version of Http. It provides better performance over Http/1. Especially with high latency networks such as cellular networks.
https://en.wikipedia.org/wiki/HTTP/2

It is completely optional, meaning that everything will work properly even if the client doesn't support it.
All modern browsers support it: http://caniuse.com/#feat=http2

The next version of jServer library will support it as well.
I will explain how to configure it when it is released. It is quite simple and transparent.
Note that Http/2 will only work with SSL connections.

The server example is already running with Http/2 enabled: https://b4x.com:51041/
The following page shows the protocol: https://b4x.com:51041/manyimages
The same non-ssl page is available here: www.b4x.com:51042/manyimages
On Chrome the speed difference is significant. On Firefox the speed is more or less the same (probably because Firefox sets a higher limit to the maximum number of concurrent connections).
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Comparison between non-ssl and ssl + http/2:

SS-2015-12-09_17.53.16.png


The load time is shown in the bottom right corner. You can also see the requests protocol. This is a good way to test it (h2 = Http/2).
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Added the load time to the example.

The ManyImages handler is a good example of how the smart strings literal makes it easy to combine html in the code (a bit like PHP):
B4X:
Sub Handle(req As ServletRequest, resp As ServletResponse)
   Dim page As StringBuilder
   page.Initialize
   Dim jo As JavaObject = req
   page.Append($"
   <html>
     <body>
       <script type="text/javascript">
         before = (new Date()).getTime();
          window.onload = function ()
        {
        var after = (new Date()).getTime();
          var sec = (after-before)/1000;
          var p = document.getElementById("total");
          p.innerHTML = sec + " seconds.";
        }
       </script>
       <h1>Protocol: ${jo.RunMethod("getProtocol", Null)}, Total Time: <span id="total">...</span></h1>
       <table style="width:100%">
         ${CreateRows}
       </table>
     </body>
   </html>
"$)
   resp.ContentType = "text/html"
   resp.Write(page.ToString)
End Sub

Private Sub CreateRows As String
   Dim sb As StringBuilder
   sb.Initialize
   For x = 1 To 10
     sb.Append($"<tr>"$).Append(CRLF)
     For y = 1 To 10
       sb.Append($"<td><img src="/smiley/smiley.png?nocache=${Rnd(1, 99999999)}"/></td>"$)
       sb.Append(CRLF)
     Next
     sb.Append("</tr>")
   Next
   Return sb.ToString
End Sub
 
Upvote 0

Pendrush

Well-Known Member
Licensed User
Longtime User
Upvote 0
Top