AuthorMessage
dzadzuks
Ametuar
Posts: 135

Would be v.cool if someone could show how to open sockets with Delphi using ClientSocket component.. or  maybe i dont need to open them  :?
 thx 
Mickey
Ametuar
Posts: 115

There is a function which downloads a URL for example:
Of course it can be also a procedure if you don't need result back.:
Code:
function TDownloadThread.DownloadFile:String;
const
  BufSize = 256;
var
  MySession, MyDownload : hInternet;
  Buf : Array[0..BufSize-1] of Char;
  BufLen : DWord;
  x,b : String;
  i : Integer;
begin
  Log('Download starting'); // Logs something :P
  BufLen := 0;
  x := '';
  b := '';
  MySession := InternetOpen(nil,INTERNET_OPEN_TYPE_PRECONFIG,nil,nil,0);
  try
    MyDownload := InternetOpenURL(MySession,PChar(Url),nil,0,0,0);
    try
      repeat
        InternetReadFile(MyDownload,@Buf,BufSize,BufLen);
        b:='';
        for i := 0 to BufLen-1 do
          b := b+Buf[i];
        x := x+b;
        Log(IntToStr(Length(x)) + ' bytes downloaded');
      until BufLen=0;
      Result := x;
    finally
      InternetCloseHandle(MyDownload);
    end;
  finally
    InternetCloseHandle(MySession);
  end;
end;

Meka][Meka
Unstopable
Posts: 700

but this example does not show clientsocket use... crappy components.....
dzad: opening new socket...
Code:

uses
     ScktComp;

Code:

var
  client : TClientSocket;
begin
  client := TClientSocket.Create(Application);
  //setting it up example...
  client.Address := 'localhost';
  client.Port := '125';
  client.Open; //connect
  //client.Socket << socket access

-/Meka][Meka