sgcWebSockets supports a wide range of protocols, HTTP/2 is the protocol which is in development right now.
HTTP 1.1 has been the most used HTTP Protocol and wide implemented in server and clients during the last 15 years. But as internet grows, applications and webs growed and the amount of loaded data increased, the shortcomings of HTTP 1.1 became more prominent. Basically one request by connection and duplication of requests.
HTTP 2 has some advantages like:
The test is very simple, just call server to get an image 100 times, one by one, so when first finishes, second request is sent and so on
procedure TestHTTP1; begin oHTTP := TIdHTTP.Create(nil); Try for i := 1 to 100 do begin oStream := TMemoryStream.Create; Try oHTTP.Get('https://ik.imagekit.io/demo/img/http_test/h_' + Format('%.2d', [i]) + '.jpg', oStream); oJPEG := TJPEGImage.Create; oJPEG.Scale := jsHalf; oStream.Position := 0; oJPEG.LoadFromStream(oStream); ... TThread.Queue(nil, procedure begin FRMHTTP2_Client.imgHTTP.Canvas.Draw(vCol * 50, vRow * 50, oJPEG); end); Finally oStream.Free; End; end; Finally oHTTP.Free; Terminate; end; end;
The test is still more simple than with HTTP 1.1, just create http2 component, and call 100 times to get request, there is no need to wait to get a response because responses are dispatched asynchronously when are received by client.
procedure TestHTTP2; var oHTTP2: TsgcHTTP2Client; begin oHTTP2 := TsgcHTTP2Client.Create; oHTTP2.OnHTTP2Response := OnHTTP2ResponseEvent; oHTTP2.Request.Accept := 'image/*,*/*;q=0.8'; for i := 1 to 100 do oHTTP2.Get('https://ik.imagekit.io/demo/img/http_test/h_' + Format('%.2d', [i]) + '.jpg'); end; procedure OnHTTP2ResponseEvent(const Connection: TsgcHTTP2ConnectionClient; const Request: TsgcHTTP2RequestProperty; const Response: TsgcHTTP2ResponseProperty); var oJPEG: TJPEGImage; vCol, vRow: Integer; begin oJPEG := TJPEGImage.Create; oJPEG.LoadFromStream(Response.Data); oJPEG.Scale := jsHalf; ... TThread.Queue(nil, procedure begin if Assigned(imgHTTP2) then begin imgHTTP2.Canvas.Draw(vCol * 50, vRow * 50, oJPEG); end; end); end;
Most probably you already know which protocol is faster, you can test yourself using the following compiled demo for windows.
NOTE: in the demo, the HTTP1.1 test runs in a secondary thread and HTTP2.0 is asynchronous so it doesn't needs to run in a secondary thread.
When you subscribe to the blog, we will send you an e-mail when there are new updates on the site so you wouldn't miss them.