Delphi-PRAXiS
Seite 2 von 2     12   

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Netzwerke (https://www.delphipraxis.net/14-netzwerke/)
-   -   Delphi Download Manager (https://www.delphipraxis.net/15493-download-manager.html)

hboy 3. Feb 2004 15:20

Re: Download Manager
 
ich lade http files so mit einem TClientSocket herunter

Delphi-Quellcode:
procedure TForm1.csConnect(Sender: TObject; Socket: TCustomWinSocket);
var
  SockStream: TWinSocketStream;
  RequestString: string;
  Buffer: Array[0..1024] of char;
begin
  memo1.Lines.Add('connect request accepted.');
  memo1.Lines.Add('requesting file '+Edit2.text);

                   RequestString:= Format('GET /%s HTTP/1.0'#13#10,[Edit2.Text]);
  RequestString := RequestString+'Accept: */*'#13#10;
  RequestString := RequestString+'Accept-Language: de'#13#10;
  RequestString := RequestString+'Accept-Encoding: none'#13#10;
  RequestString := RequestString+'Accept-Range: bytes'#13#10;
  RequestString := RequestString+'User-Agent: Monster/1.0 (compatible; MSIE 5.01; Windows NT 8.0)'#13#10; // ;-)
  RequestString := RequestString+'Host: '+form1.Edit1.text+#13#10;
  RequestString := RequestString+'Connection: Keep-Alive'#13#10#13#10#13#10;

  SockStream := TWinSocketStream.Create(cs.Socket,60000);
  SockStream.Write(RequestString[1], Length(RequestString));
  //Sockstream.Read(Buffer,SizeOf(Buffer));

  now := gettickcount;

  while (SockStream.Read(Buffer, SizeOf(Buffer)) <> 0) do
      begin
        memo1.Lines.Add('Received '+inttostr(SizeOf(Buffer))+' Bytes');
        FData := FData+ Buffer;
        FillChar(Buffer, SizeOf(Buffer), #0);
        // Check for closure of the socket or timeout
        if (gettickcount > now+10000) OR not cs.Active then
        Exit;
  end;

  memo1.Lines.Add('printing buffer...');
  browse.Lines.Add(FData);

  //memo1.Lines.Add('Extracting IP');
  //ip := extractip(FData);
  //memo1.Lines.Add(ip);

  memo1.Lines.Add('Terminating Session');
  cs.Socket.Close;
  cs.Active := false;
  SockStream.Free;


end;

hboy 3. Feb 2004 15:49

Re: Download Manager
 
verbinden geht so


Delphi-Quellcode:
procedure TForm1.downloadClick(Sender: TObject);
begin
  //memo1.Clear;
  //browse.Clear;
  cs.Service := 'http';
  cs.Host:= Edit1.Text;
  cs.Port:= 80;
  cs.ClientType := ctBlocking; //<-- ganz wichtig
  FData := '';
  //memo1.Lines.Add('Start Connection');
  cs.Active:= true;

end;

hboy 4. Feb 2004 18:38

Re: Download Manager
 
kappt das nun?


Alle Zeitangaben in WEZ +1. Es ist jetzt 05:34 Uhr.
Seite 2 von 2     12   

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz