How to do continuous GET with TFPHTTPClient lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- Pascal · 2022-03-22 07:27 Hi, i would like to implement a thread which listens to docker events (https://docs.docker.com/engine/api/v1.41/#operation/SystemEvents). What functions do i need to use to achieve this? The normal Get will probably not return. Regards Pascal ---------------------------------------------------------------------- Pascal · 2022-03-29 08:00 No one? ---------------------------------------------------------------------- rvk · 2022-03-29 09:56 I don't think this is easily done with TFPHTTPClient. My first instinct would be to use something like the OnDataReceived event to examine the received data wile the GET is still going. But the problem is that OnDataReceived doesn't give back the received data but only the number of bytes received. And the FBuffer (in which the data really sits at that moment) is defined private. Also I think the FBuffer is written to the stream AFTER this event. So you probably better off to just open a connection yourself and do the reading of the data yourself. ---------------------------------------------------------------------- Pascal · 2022-03-29 12:36 Good idea, maybe a descendant of TFPCustomHTTPClient. I haven't seen such continuous GETs in other REST APIs but maybe better than webhooks. ---------------------------------------------------------------------- rvk · 2022-03-29 12:44 Quote from: Pascal on March 29, 2022, 02:36:58 pmGood idea, maybe a descendant of TFPCustomHTTPClient. I haven't seen such continuous GETs in other REST APIs but maybe better than webhooks. Yes, I kinda thought the same thing after thinking about it some. The ReadFromSocket() is just in the protected part so it can be overriden. Something like this could work: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type  TFPHTTPClient = class(fphttpclient.TFPCustomHTTPClient)  protected    function ReadFromSocket(var Buffer; Count: Longint): Longint; override;  end; function TFPHTTPClient.ReadFromSocket(var Buffer; Count: Longint): Longint;var  S: String;begin  inherited;  // do something with Bufferend; procedure TForm1.Button1Click(Sender: TObject);var  http: TFPHttpClient;begin  http := TFPHttpClient.Create(nil);  try    http.Get('your_site'); // no need for result because everything is processed in ReadFromSocket()  finally    http.Free;  end; end; Note... You might want to reset the stream inside ReadFromSocket() once in w while otherwise that could grow to huge proportions (and you don't use it anyway) (and you can't set Count to 0 in ReadFromSocket because it's not a var)