Re: Is there standard way of streaming unknown amount of data over HTTP

Giganews Newsgroups
Subject: Re: Is there standard way of streaming unknown amount of data over HTTP
Posted by:  Remy Lebeau \(Indy Team\) (no.spam@no.spam.com)
Date: Tue, 15 Jan 2008

"Tommi Prami" <tommi.nospam.prami@poista.ecomond.com> wrote in message
news:56F146DEE844E340tommi.nospam.prami@poista.ecomond.com...

> I was just pondering that is there a way to send data from the
> server (standard way) before I know how much of it will be.
>
> so if my data producer, let's say XML, will produce blocks of
> data, could I send each block from server side without building
> the whole data to server memory and send it at one go?

You have to know the data size ahead of time in order to set the
'Content-Length' response header.  HTTP is not a streaming protocol.  But in
any case, TIdHTTPServer does allow you to manually send your own data
chunks.  Inside the OnCommandGet event handler, call
AResponseInfo.WriteHeader() after setting the necessary header values, and
then send all of the data chunks before exiting the handler.  Do not set the
AResponseInfo's ContentText or ContentStream properties.

The alternative is to derive your own TStream class that overrides the
virtual Read() method to deliver the chunks from the provider.  You could
then set the AResponseInfo.ContentStream property and let the server handle
the sending for you.

> Just that if the data block will get HUGE then few of hose calls will
> more than less kill the server if there is no time to "swap" data to
> disk and send it as File Stream.

You don't need to use a file at all.  You could use a TMemoryStream instead,
or you don't want to manage the chunk sending manually, and have plenty of
memory to spare.

Gambit

Replies

None

In response to

Is there standard way of streaming unknown amount of data over HTTP posted by Tommi Prami on Wed, 16 Jan 2008