Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Thanks to GrandmasterB, here is the code I've managed to put together: (it's in my thread's Execute block)</p> <pre><code>var Buffer: array [0..1024 - 1] of Char; SocketStream: TWinSocketStream; RequestString: String; BytesRead: Integer; begin try ClientSocket.Active := true; DownloadedData := ''; FillChar(Buffer, SizeOf(Buffer), #0); if not Terminated then begin // Wait 10 seconds SocketStream := TWinSocketStream.Create(ClientSocket.Socket, 10000); try // Send the request to the webserver RequestString := 'GET /remotedir/remotefile.html HTTP/1.0'#13#10 + 'Host: www.someexamplehost.com'#13#10#13#10; SocketStream.Write(RequestString[1], Length(RequestString)); // We keep waiting for the data for 5 seconds if (not Terminated) and SocketStream.WaitForData(5000) then repeat // We store the data in our buffer BytesRead := SocketStream.Read(Buffer, SizeOf(Buffer)); if BytesRead = 0 then break else DownloadedData := DownloadedData + Buffer; until Terminated or (not SocketStream.WaitForData(2000)); finally // Close the connection SocketStream.Free; if ClientSocket.Active then ClientSocket.Active := false; end; end; except end; </code></pre> <p>You have to put this to the constructor of the thread:</p> <pre><code> ClientSocket := TClientSocket.Create(nil); ClientSocket.Host := 'www.someexamplehost.com'; ClientSocket.Port := 80; ClientSocket.ClientType := ctBlocking; inherited Create(false); // CreateSuspended := false; </code></pre> <p>And this to the desctructor:</p> <pre><code> ClientSocket.Free; inherited; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload