Downloading a file (httpsocket)

I use the second form to download a file:

HTTPSocket.Get ( URL As String, File As FolderItem )

It works fine unless I do not have an internet connection, in that case the application freeze. And this is bad.

I tried to check .IsConnected, but I never am able to download anything with the code below.

Can you told me what is wrong ?

[code] Dim MySocket As New HTTPSocket

If Not MySocket.IsConnected Then
  TF_Report.Text = "This computer is not connected to internet."      
  Return False
End If

MySocket.Get(DownloadURL, DownloadFI)

MySocket.Close[/code]

DownloadFI is correct: the file is created, but nothing goes into it.

Also, before the code above, I always get troubles after the first file download (or so).

The use of MySocket.Close seems to be responsible of the trouble… A previous version of the project does not have it and the file is downloading…

HTTP is connectionless, so neither IsConnected or Closed are of much use (and can be dangerous as you have discovered). It would be nice if they could be hidden/disabled, but it is what it is. Determining whether you are connected to the internet (as opposed to being connected to a local network) is difficult. There have been a few discussions about it. You may have to search the old forums as well.

A quick way of finding out if one is connected to the internet is simply to download the Google homepage. I am sure there are more elaborate ways, but that one is simple and robust.

Won’t that have the same delay issue as the OP is complaining about? Most of the ways of determining if you’re connected to the internet involve timing out, with the inherent app freeze that goes with it.

The app freeze is probably due to synchronous mode. I bet using asynchronous would solve the issue.

Tim, Michel: thank you for your kind answers.

No, the freeze comes when I am not connected to the internet AND (if I am connected,) when I ask to download a second file. Usually (*) the first file download goes fine.

  • If the link points to a file; if it links to an html (or other non archive types), asking for identification, the connection fail downloading that html file.

Now I know why I do not wanted to add a simple download feature to that project.

Any other idea(s) ?

I am (trying to) debug the application on Windows 8 and I found one or two funy things:

a. The Progress Bar:
it is thin (vertically) and blue on OS X (Yosemite)
It is taller (than OS X) and green on Windows 8.1

b. Editing a Cell (thanks to the ones that helped me on this because I went all wrong):
The ListBox’ focus is lost after the Cell editing (OS X Yosemite), but the focus stays on the ListBox on Windows 8.1 !

c. Downloading more than one file at a time:
On OS X Yosemite, I seem to be able to download - at the same time - two files. Seems because the second file is larger than the first one and the download is still running.

I confirm that I am able to download more than one file at the same time (parallel downloadings) on both OS X and Windows.

Talking about Windows, I do not had troubles donwloading arround 10 files (excepted that I do not know - yet - where I put them ;-:slight_smile: ).

Unfortunately, I do not had time to make a real testing (full testings).