Recent

Author Topic: [Solved] What are the alternatives to URLOpenBlockingStream.  (Read 2813 times)

loaded

  • Hero Member
  • *****
  • Posts: 568
[Solved] What are the alternatives to URLOpenBlockingStream.
« on: November 06, 2021, 09:29:05 am »
Hi All,
With the code in the example, I am downloading an image from the https site using the URLOpenBlockingStream method.
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var    //  add uses activex,comobj,urlmon,
  3.   ExchangeStream: IStream;
  4.   Pngstream: TOleStream;
  5.   crono:Cardinal;
  6.   furl:string;
  7. begin
  8. crono:=GetTickCount;
  9.    furl:='https://tile.openstreetmap.de/7/63/42.png';   //  https://wiki.openstreetmap.org/wiki/Tile_servers
  10.    if (URLOpenBlockingStream(nil, pchar(furl),ExchangeStream,0,nil)=0) then
  11.    begin
  12.    Pngstream:=TOleStream.Create(ExchangeStream);
  13.    image1.picture.LoadFromStream(Pngstream);
  14.    end;
  15.  TButton(sender).Caption:=FloatToStr((GetTickCount-crono)/1000);  // about 0.031~ seconds
  16. end;

This code downloads the image in the link in about 0.031~ seconds, uploads the Image and displays it.
I have an application like leaflet  https://leafletjs.com/in my mind, for this, while I'm just at the beginning, I want to discover the fastest download method suitable for thread use. I will lay the groundwork for this today :)
What alternatives to URLOpenBlockingStream can be used for this?
Any ideas you share will be very valuable to me. Respects.
« Last Edit: November 12, 2021, 02:48:16 pm by loaded »
If Ide=Lazarus 2.0.10 32 Bit and Os=Win 10 Home 64 Bit then Get up and do something useful! Because God is the helper of those who start again;

Thaddy

  • Hero Member
  • *****
  • Posts: 11516
Re: What are the alternatives to URLOpenBlockingStream.
« Reply #1 on: November 06, 2021, 10:32:13 am »
A pure blocking alternative is synapse 4.1
There are more alternatives:
packages:
fcl-web/fcl-net
gnutls
Indy
libcurl

and probably more.

All the packages mentioned are cross platform and all come with examples.

You may want to choose one of these anyway, because they are not tied to windows.
I guess the speed is more likely to be dependent on connection and internet speed. Less so on which method you use.

My own preference is currently fcl-web/fcl-net because it is maintained by the core fpc team and pure Pascal. (or synapse, but fcl-web/fcl-net is very similar).

Except for synapse all come with FPC/Lazarus as standard.

Note that on windows only URLOpenBlockingStream  may be slightly faster, but still x-platform is a better option to me.
« Last Edit: November 06, 2021, 10:50:23 am by Thaddy »
Путин преступник. Россияне дезинформированы.

loaded

  • Hero Member
  • *****
  • Posts: 568
Re: What are the alternatives to URLOpenBlockingStream.
« Reply #2 on: November 06, 2021, 05:17:38 pm »
Thaddy Master, thank you for spending your valuable time and sharing your valuable experience.
This information became like lights on the road. They're pretty good for a start.
If Ide=Lazarus 2.0.10 32 Bit and Os=Win 10 Home 64 Bit then Get up and do something useful! Because God is the helper of those who start again;

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1963
  • Former Delphi 1-7, 10.2 user
Re: What are the alternatives to URLOpenBlockingStream.
« Reply #3 on: November 06, 2021, 10:29:43 pm »
For Windows, my favourite is the WinInet API because it avoids OpenSSL DLL hell.
Lazarus 2.3, FPC 3.3.1 macOS 12.3.1 x86_64 Xcode 13.3.1
Lazarus 2.3, FPC 3.3.1 macOS 12.3.1 aarch64 Xcode 13.3.1

loaded

  • Hero Member
  • *****
  • Posts: 568
Re: What are the alternatives to URLOpenBlockingStream.
« Reply #4 on: November 12, 2021, 02:48:02 pm »
Thaddy and trev who replied, thank you as much as the number of letters in your messages.
After extensive experimentation, I decided to use WinINet.
-Almost the same speed as Chrome.
-In different windows versions, also different http and https servers work without problems.
-No Dll dependencies
For now, these are very, very good enough for me.
Also, what I learned was extra.
If Ide=Lazarus 2.0.10 32 Bit and Os=Win 10 Home 64 Bit then Get up and do something useful! Because God is the helper of those who start again;

 

TinyPortal © 2005-2018