Thema: Delphi Download Manager

Einzelnen Beitrag anzeigen

hboy

Registriert seit: 16. Jan 2004
364 Beiträge
 
#11

Re: Download Manager

  Alt 3. Feb 2004, 16:20
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;
Power is nothing without TControl
  Mit Zitat antworten Zitat