🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.internet.socket
Article #3817

Re: ClientSocket; Downloading a file from internet

#3817
From: Param
Date: Sat, 30 Apr 2005 13:32
82 lines
3748 bytes
Thanx Remy,
The code worked but i think better i should shift to Indy.

cheers
Nirvana

Remy Lebeau (TeamB) wrote:
> "Param" <param_nirvana@yahoo.com> wrote in message
> news:4272c790@newsgroups.borland.com...
> 
> 
>>    ClientSocket1->Address = "195.190.132.10";
> 
> 
> Use the Host property instead:
> 
>     ClientSocket1->Host = "www.national-lottery.co.uk";
> 
> 
>>    ClientSocket1->Active = true;
>>
>>    if( ClientSocket1->Active )
> 
> 
> You did not specify whether you are using the socket in blocking or
> non-blocking mode.  If non-blocking, then that condition will almost always
> be false since the socket does not actually connect right away.  You should
> move the downloading code into the socket's OnConnect event instead, ie:
> 
>     void __fastcall TForm1::Button1Click(TObject *Sender)
>     {
>         if( ClientSocket1->Active )
>             ClientSocket1->Active = false;
> 
>         ClientSocket1->Port = 80;
>         ClientSocket1->Address = "195.190.132.10";
> 
>         try {
>             ClientSocket1->Active = true;
>         }
>         catch(const Exception &) {
>             ListBox1->AddItem("Exception", this);
>         }
>     }
> 
>     void __fastcall TForm1::ClientSocket1Connect(TObject *Sender,
> TCustomWinSocket *Socket)
>     {
>         ListBox1->AddItem("Connected", this);
> 
>         // you must specify the leading backslash when specifying the file
>         // to download, and you must use CRLF, not LF alone, for all
>         // line breaks...
> 
>         try
>         {
>             Socket->SendText("GET /player/files/EuroMillions.csv
> HTTP/1.0\r\n\r\n");
>             //...
>         }
>         catch(const Exception &) {
>             ListBox1->AddItem("Exception", this);
>         }
>     }
> 
> 
> Now, with that said, the actual responses from the server need to be handled
> in the socket's OnRead event.
> 
> However, do note that using TClientSocket in non-blocking mode, if you are
> indeed doing so, will make the processing quite complicated to code for.
> Even in blocking mode, HTTP in general is a complex protocol to implement
> manually.  You would be MUCH better off not using TClientSocket at all.
> There are plenty of third-party HTTP components available that do all of the
> hard work for you.  Indy (http://www.indyproject.org) and ICS
> (http://www.overbyte.be) are amongst the popuplar choices that include HTTP
> support (amongst other things).
> 
> 
> Gambit
> 
> 
Technical Details
Message-ID: <427388de$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!newshub.sdsu.edu!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!feed5.newsreader.com!newsreader.com!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!news-in.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail
References: <4272c790@newsgroups.borland.com> <4272dade$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,100e2486fa6e2fb2
X-Google-Attributes: gid11508e,public
X-Google-Language: ENGLISH,ASCII-7-bit
Date: Sat, 30 Apr 2005 14:32:13 +0100
From: Param <param_nirvana@yahoo.com>
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.2) Gecko/20040804 Netscape/7.2 (ax)
X-Accept-Language: en-us, en
MIME-Version: 1.0
Newsgroups: borland.public.cppbuilder.internet.socket
Subject: Re: ClientSocket; Downloading a file from internet
References: <4272c790@newsgroups.borland.com> <4272dade$1@newsgroups.borland.com>
In-Reply-To: <4272dade$1@newsgroups.borland.com>
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 84.67.13.8
Message-ID: <427388de$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1114867934 84.67.13.8 (30 Apr 2005 06:32:14 -0700)
Lines: 82
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!newshub.sdsu.edu!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!feed5.newsreader.com!newsreader.com!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!news-in.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail