Hello everyone,
I need to fetch just a short string from a webserver and I am doing so with the lNet TLHTTPClientComponent. Everything works like a charm, just not setting the timeout. In the object inspector it always jumps to 0, in the code it seems not to have any effect. What am I doing wrong?
Thanks!
procedure TAboutForm.SomeButtonClick(Sender: TObject);
begin
HTTPBuffer := '';
HTTPFinished := false;
HTTPError := '';
CheckUpdateLHTTPClient.Host := 'www.something.net';
CheckUpdateLHTTPClient.URI := '/test.txt';
CheckUpdateLHTTPClient.Port := 809; // Meant to produce a timeout
CheckUpdateLHTTPClient.Timeout:= 5; // seconds or what?
CheckUpdateLHTTPClient.SendRequest;
// Wait until OnDoneInput or OnError
while (not HTTPFinished)
do Application.ProcessMessages;
if (Length(HTTPError) = 0) then begin
MessageDlg(HTTPBuffer, mtInformation, [mbOk], 0);
end
else
MessageDlg(HTTPError, mtError, [mbOk], 0);
end;
procedure TAboutForm.CheckUpdateLHTTPClientDisconnect(aSocket: TLSocket);
begin
HTTPFinished := true;
end;
procedure TAboutForm.CheckUpdateLHTTPClientDoneInput(ASocket: TLHTTPClientSocket);
begin
ASocket.Disconnect;
end;
procedure TAboutForm.CheckUpdateLHTTPClientError(const Msg: string; ASocket: TLSocket);
begin
HTTPError:=Msg;
HTTPFinished:=true;
ASocket.Disconnect; // REQUIRED?
end;
function TAboutForm.CheckUpdateLHTTPClientInput(ASocket: TLHTTPClientSocket; ABuffer: pchar; ASize: integer): integer;
var
OldLength: dword;
begin
OldLength := Length(HTTPBuffer);
SetLength(HTTPBuffer, OldLength + ASize);
Move(ABuffer^, HTTPBuffer[OldLength + 1], ASize);
Result := ASize; // tell the http buffer we read it all
end;