🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.internet.socket
3 messages
3 total messages Started by bar Tue, 04 Mar 2008 10:07
DownloadFiles
#478
Author: bar
Date: Tue, 04 Mar 2008 10:07
53 lines
2100 bytes
Hi Remy,

I am the following code to download files from the
HTTP server. (BCB 6 and Indy 9.? stable version)

TldHTTP is dropped at design time.
Properties set at design time

ConnectTimeout = 0
HandleRedirects = true

Request
    Connection = Keep-Alive

void TForm1::DownloadFile(String URL,AnsiString FileName)
{
    try
    {
        std::auto_ptr<TFileStream> strm(new TFileStream(FileName,fmCreate));

        HTTP->Request->Pragma = "no-cache";
        HTTP->HandleRedirects = true;
        Application->ProcessMessages();
        HTTP->Get(URL, strm.get());
    }
    catch(const Exception &E)
    {
        ShowMessage(E.Message);
    }
}

I call this function repeatedly with different parameter and its working 
fine.

I have some questions

1.I didn't see any Connect()/Disconnect() function in the code but still 
working. How?. Does it makes difference.
2.Is it good to add these statements when exception occurs.
    catch(const Exception &E)
    {
            if(HTTP->Connected())
                HTTP->Disconnect();
            ShowMessage(E.Message);
    }

Finally i want to use this function in a loop. So i want to know the best 
way to code.

All help greatly appreciated.

Thanks
SA 
Re: DownloadFiles
#482
Author: Remy Lebeau (TeamB)
Date: Tue, 04 Mar 2008 17:37
15 lines
1262 bytes
"bar" <shaikakbar250281@yahoo.co.in> wrote in message 
news:47cd1f44@newsgroups.borland.com...

> I didn't see any Connect()/Disconnect() function in the code
> but still working. How?

Get() calls them internally for you.

> 2.Is it good to add these statements when exception occurs.

That is not needed.  Get will Disconnect() internally for you.


Gambit 
Re: DownloadFiles
#286
Author: bar
Date: Tue, 18 Mar 2008 16:51
31 lines
1584 bytes
Hi Remy thanks for reply.
sorry for the delay

I want to download a file of 100 kb regularly at an interval of 1 minute.

As i see when repeatedly calling function, program is not responding.
I try to represent my code.

void TForm1::DownloadFile(String URL,AnsiString FileName)
{
    try
    {
        std::auto_ptr<TFileStream> strm(new TFileStream(FileName,fmCreate));

        HTTP->Request->Pragma = "no-cache";
        HTTP->HandleRedirects = true;
        HTTP->Get(URL, strm.get());
    }
    catch(const Exception &E)
    {
         return;
    }
}

void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
    DownloadFile("http://url",abc)
}

Thanks
SA 
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads