Witam, szukam skutecznej metody sprawdzania połączenia z internetem takiej która mogła by działać w pętli lub w timerze co kilka sec i zwracała do wartość true (connect) lub false (disconnect) w zależności od statusu połączenia z internetem.
Ma ktoś jakiś dobry pomysł?
Metoda którą stosuje to:
For example,
uses WinInet;
function DownloadFile(const Url: string): string;
var
NetHandle: HINTERNET;
UrlHandle: HINTERNET;
Buffer: array[0..1024] of Char;
BytesRead: dWord;
begin
Result := '';
NetHandle := InternetOpen('Delphi 5.x', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
if Assigned(NetHandle) then
begin
UrlHandle := InternetOpenUrl(NetHandle, PChar(Url), nil, 0, INTERNET_FLAG_RELOAD, 0);
if Assigned(UrlHandle) then
{ UrlHandle valid? Proceed with download }
begin
FillChar(Buffer, SizeOf(Buffer), 0);
repeat
// Result := Result + Buffer; (tu wstawiam procedure reconnect)
FillChar(Buffer, SizeOf(Buffer), 0);
InternetReadFile(UrlHandle, @Buffer, SizeOf(Buffer), BytesRead);
until BytesRead = 0;
InternetCloseHandle(UrlHandle);
end
else
{ UrlHandle is not valid. Raise an exception. }
raise Exception.CreateFmt('Cannot open URL %s', [Url]);
InternetCloseHandle(NetHandle);
end
else
{ NetHandle is not valid. Raise an exception }
raise Exception.Create('Unable to initialize Wininet');
end;
z tym że program po godzinnym działaniu wywala komunikat: "brak miejsca dla wykonania tego polecenia" domyslam się że przyczyną jest to że nie zwalniam biblioteki winsock? lub ze program działa w timerze co kilka sec:
procedure Tkk.PingerTimerTimer(Sender: TObject);
begin
begin
DownloadFile('http://www.google.pl');
end;
end;
Ktoś może wie jak to zaprogramować żeby co np. 15sec sprawdzać połączenie przez funkcję "DownloadFile('http://www.google.pl');"
i żeby program działał stabilnie?