I created a simple website monitoring application using the Indy TIdhttp component. I want to determine when the specified page does not return for a certain period of time (I use 5000 milliseconds). As a test, I created a page on a website that intentionally takes 15 seconds to respond. But I can’t get my procedure to “give up” after 5 seconds. I tried ReadTimeout , the proposed solution using the timer and the OnWorkBegin event (it would never be able to get OnWorkBegin to get fire right after the call).
Note I am not worried about the connection timeout. I am concerned about the timeout when the server returns with the page.
Here is some source code that I used. It contains many elements that I refer to.
procedure TServLogic.WorkBegin(ASender: TObject; AWorkMode: TWorkMode; AWorkCountMax: Int64); begin GetTimer.Enabled := True; end; procedure TServLogic.WorkEnd(ASender: TObject; AWorkMode: TWorkMode); begin GetTimer.Enabled := False; end; procedure TServLogic.GetTimerTimer(Sender: TObject); begin idHttp.Disconnect(True); end; procedure TServLogic.CallHttp(mlink: String): String; begin result := ''; GetTimer := TTimer.create(nil); GetTimer.OnTimer := GetTimerTimer; GetTimer.Interval := 5000; try IdHTTP := TIdHTTP.create(nil); idhttp.ReadTimeout := 5000; IdHttp.OnWorkBegin := WorkBegin; IdHttp.OnWorkEnd := WorkEnd; try result := idhttp.get(mLink); except on e:exception do begin AppendToLog('Server did not respond withing 5 seconds'); end; end; finally GetTimer.Free; idhttp.free; end; end;
delphi indy
M schenkel
source share