[Socket] ServerSocket i ClientSocket??

0

Mam pytanie. Jak za pomocą komponentów ServerSocket i ClientSocket pobrać kod źródłowy strony WWW?

0

Form1, Memo1, Button1

function GetSource(address:string; port:word):string;
var s:string;
    cl:integer;
    pc:pchar;
begin
cl:=0;
with TTCPClient.Create(nil) do
  begin
  RemoteHost:=address;
  RemotePort:=IntToStr(port);
  Active:=TRUE;
  Sendln('GET / HTTP/1.0');
  Sendln('');
  repeat
  s:=Receiveln();
  if Pos('Content-Length: ', s)=1 then
    begin
    Delete(s, 1, length('Content-Length: '));
    cl:=StrToInt(s);
    end;
  until s='';
  GetMem(pc, cl);
  ReceiveBuf(pc^, cl);
  result:=pc;
  FreeMem(pc, cl);
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
Memo1.Text:=StringReplace(GetSource('www.4programmers.net', 80), #$A, #$D#$A, [rfReplaceAll]);
end;

1 użytkowników online, w tym zalogowanych: 0, gości: 1