Jump to content

how check internet connection unigui


SayeyeZohor

Recommended Posts

The only "reliable" way is to try get some data from a server of your choice:

function TMainF.isInternetConnection: Boolean;
begin
  try
    IdHTTP.Get('http://www.svtech.cz');
  except
    on E: Exception do begin
      if not (E is EIdHTTPProtocolException) then begin
        Result := False;
        Exit;
      end;
    end;
  end;
  Result := True;
end;

 

  • Upvote 1
Link to comment
Share on other sites

4 hours ago, Ron said:

The only "reliable" way is to try get some data from a server of your choice:


function TMainF.isInternetConnection: Boolean;
begin
  try
    IdHTTP.Get('http://www.svtech.cz');
  except
    on E: Exception do begin
      if not (E is EIdHTTPProtocolException) then begin
        Result := False;
        Exit;
      end;
    end;
  end;
  Result := True;
end;

 

tnx

@Sherzod

Link to comment
Share on other sites

I found a older topic but did not try it

What is URL.DLL?

The file named URL.DLL is developed by Microsoft Corporation. The file is used by the Internet Explorer and the shell extension module. IE is the basic internet browser on all Windows platforms. The DLL is safe and it receives prompt security updates. The threat level of the file is found to be 1.

URL.DLL is located in C:\Windows\System32\url.dll.

Quote

 

Answer:
To make sure in this point you need to import InetIsOffline function from URL.DLL:

function InetIsOffline(Flag: Integer): Boolean; stdcall; external 'URL.DLL';

and then simply call this function in place you want to check connection status:

if InetIsOffline(0) then
   ShowMessage('This computer is not connected to Internet!')
else
   ShowMessage(You are connected to Internet!');

This function return TRUE if the local system isn't connected to Internet, or FALSE if it's connected or no attempt has been yet made to connect.

Notes:
Variable Flag is ignored, so always use zero.
This DLL is usual installed on most computers. 

 

 

 

 

Link to comment
Share on other sites

Please realize that InetIsOffline function is not reliable, as this is what
signals the tray internet status icon, and I guess we've all experienced times
when the status claimed we had internet access while we did not have it.

There is potentially much lag in that function, in my experience.

The point of checking for internet connection is to be sure you have it,
or sure you don't have it. To know this you actually have to try to get
some data from an outside server, or preferrably several servers as the
one server you check may be down. You can use a list of servers.

Internet is a living thing where devices come in and drop out all the time,
so "internet access" is a rather vague term. Define the internet?
Even Google has been down for a little while, several times...

Link to comment
Share on other sites

On 12/12/2019 at 4:36 PM, Ron said:

The only "reliable" way is to try get some data from a server of your choice:


function TMainF.isInternetConnection: Boolean;
begin
  try
    IdHTTP.Get('http://www.svtech.cz');
  except
    on E: Exception do begin
      if not (E is EIdHTTPProtocolException) then begin
        Result := False;
        Exit;
      end;
    end;
  end;
  Result := True;
end;

 

tnx, but sometimes not working ...

Link to comment
Share on other sites

  • 2 weeks later...

You have to check a server which is usually online,
or a list of servers if you cannot be certain of a single server.

In principle you can never rely fully on a single server,
as hardware/technology by nature cannot be trusted 100%.

If you have a list of ten servers, and half of them reply
correctly, you can probably assume that you are connected.

If none of them reply at all, chances are that you may not be connected.

You can check DNS servers, but even they go down at times,
but usually not for long. Google's DNS's are at 8.8.8.8 and 8.8.4.4.

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...