tags:

views:

158

answers:

1

I have built a simple website monitoring application using Indy TIdhttp component. I want to detect when a designated page is not returned within a specified time frame (I am using 5000 milliseconds). As a test I created a page on a web site which intentionally takes 15 seconds to respond. But I can't get my procedure to "give up" after the 5 seconds. I have tried ReadTimeout, a suggested solution using a timer and the OnWorkBegin event (was never able to get OnWorkBegin to fire immediately after the get call).

Note I am not worried about a connection timeout. My concern here is a timeout for the server to return with a page.

Here is some source code I have been using. It contains many of the elements I reference.

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;
A: 

I eventually got the answer based on the comments of Rob Kennedy. I tried numerous times to contact him and request he make a "formal" answer so that I could give him the vote. Never heard back.

M Schenkel