You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by nitin singh <xm...@gmail.com> on 2010/09/21 11:36:16 UTC

sending/streaming audio data using chunked encoding

Hi,
I am trying to stream real time audio data (usual length will be < 30
seconds) using http chunking. Specifially, the client will do a Post request
with TransferEncoding set as chunked in http 1.1.
- I have a thread which reads data from the codec and puts it into a shared
buffer.
- Another thread will read the data from the shared buffer and writes it in
the http chunk.
I have successfully done above using Java HttpUrlConnection class. However,
now we need to do above using https and I started looking at the HttpClient
classes. I have read all the documentation etc but am not clear how in real
time I can send data. Specifically,
- RequestEntity should not be buffered and cannot be repeatable. Also.
RequestEntity.getContentLength is not known.
- HttpClient.Execute looks a synchronous call  which writes data all at one.
It does not help since I write data only when its available.

Has anyone done this before using HttpClient?
Thanks in advance!
N

Re: sending/streaming audio data using chunked encoding

Posted by AT Pune <an...@googlemail.com>.
Hi Nitin,

I'm very new to the HTTP world and am also facing somewhat similar issue.
Currently I'm trying to implement it on HTTP. Once it is successful then I
will need to do it over HTTPS.

This is my requirement.

1. Chunk a large file (of > 3 GB size) into smaller pieces. Chunk size
should be configurable.
2. Open an output stream on Cloud URL.
3. Stream these chunks one by one to this output stream.

If you can shed more light on how you achieved your result using
ChunkedOutputStream or EntitySerializer then it will be of great help.

Thanks,
Anurag


nitin singh wrote:
> 
> Thanks Oleg. Thats exactly what I decided to do :). Sebbs suggestion can
> work but creating a HttpEntity gives me full control in writeTo method
> where
> I can copy the buffer in OutputStream (which is actually
> ChunkedOutputStream).
> Reading the code of InputStreamEntity and EntitySerializer helped :).
> 
> 
> 
> 
> On Wed, Sep 22, 2010 at 8:18 AM, Oleg Kalnichevski <ol...@apache.org>
> wrote:
> 
>> On Tue, 2010-09-21 at 21:27 +0100, sebb wrote:
>> > On 21 September 2010 20:03, nitin singh <xm...@gmail.com> wrote:
>> > > Thanks Sebb for replying to my question. I had already gone though
>> that
>> > > example. Can you be a little more specific?
>> > > - As I said I need to write data from a buffer when it gets
>> available.
>> > > So I need a OutputStream while the example you mention below builds
>> from an
>> > > InputStreamEntity.
>> >
>> > AIUI, you don't write to the output - HttpClient reads from the
>> > InputStream when it wants more data.
>> >
>> > One way to do this is to create an InputStream that reads from your
>> buffer.
>> >
>> > If the buffer is not ready, return 0 bytes.
>> >
>> > At end, return -1.
>> >
>>
>> Another way is build a custom HttpEntity that generates content
>> dynamically and writes it out to OutputStream instance passed to the
>> HttpEntity#writeOut() method without providing an implementation for the
>> HttpEntity#getContnent().
>>
>> Oleg
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
>> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>>
>>
> 
> 

-- 
View this message in context: http://old.nabble.com/sending-streaming-audio-data-using-chunked-encoding-tp29767738p29936583.html
Sent from the HttpClient-User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: sending/streaming audio data using chunked encoding

Posted by nitin singh <xm...@gmail.com>.
Thanks Oleg. Thats exactly what I decided to do :). Sebbs suggestion can
work but creating a HttpEntity gives me full control in writeTo method where
I can copy the buffer in OutputStream (which is actually
ChunkedOutputStream).
Reading the code of InputStreamEntity and EntitySerializer helped :).




On Wed, Sep 22, 2010 at 8:18 AM, Oleg Kalnichevski <ol...@apache.org> wrote:

> On Tue, 2010-09-21 at 21:27 +0100, sebb wrote:
> > On 21 September 2010 20:03, nitin singh <xm...@gmail.com> wrote:
> > > Thanks Sebb for replying to my question. I had already gone though that
> > > example. Can you be a little more specific?
> > > - As I said I need to write data from a buffer when it gets available.
> > > So I need a OutputStream while the example you mention below builds
> from an
> > > InputStreamEntity.
> >
> > AIUI, you don't write to the output - HttpClient reads from the
> > InputStream when it wants more data.
> >
> > One way to do this is to create an InputStream that reads from your
> buffer.
> >
> > If the buffer is not ready, return 0 bytes.
> >
> > At end, return -1.
> >
>
> Another way is build a custom HttpEntity that generates content
> dynamically and writes it out to OutputStream instance passed to the
> HttpEntity#writeOut() method without providing an implementation for the
> HttpEntity#getContnent().
>
> Oleg
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>
>

Re: sending/streaming audio data using chunked encoding

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Tue, 2010-09-21 at 21:27 +0100, sebb wrote:
> On 21 September 2010 20:03, nitin singh <xm...@gmail.com> wrote:
> > Thanks Sebb for replying to my question. I had already gone though that
> > example. Can you be a little more specific?
> > - As I said I need to write data from a buffer when it gets available.
> > So I need a OutputStream while the example you mention below builds from an
> > InputStreamEntity.
> 
> AIUI, you don't write to the output - HttpClient reads from the
> InputStream when it wants more data.
> 
> One way to do this is to create an InputStream that reads from your buffer.
> 
> If the buffer is not ready, return 0 bytes.
> 
> At end, return -1.
> 

Another way is build a custom HttpEntity that generates content
dynamically and writes it out to OutputStream instance passed to the
HttpEntity#writeOut() method without providing an implementation for the
HttpEntity#getContnent().

Oleg



---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: sending/streaming audio data using chunked encoding

Posted by sebb <se...@gmail.com>.
On 21 September 2010 20:03, nitin singh <xm...@gmail.com> wrote:
> Thanks Sebb for replying to my question. I had already gone though that
> example. Can you be a little more specific?
> - As I said I need to write data from a buffer when it gets available.
> So I need a OutputStream while the example you mention below builds from an
> InputStreamEntity.

AIUI, you don't write to the output - HttpClient reads from the
InputStream when it wants more data.

One way to do this is to create an InputStream that reads from your buffer.

If the buffer is not ready, return 0 bytes.

At end, return -1.

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: sending/streaming audio data using chunked encoding

Posted by nitin singh <xm...@gmail.com>.
Thanks Sebb for replying to my question. I had already gone though that
example. Can you be a little more specific?
- As I said I need to write data from a buffer when it gets available. So I
need a OutputStream while the example you mention below builds from an
InputStreamEntity.
- Also, once I call HtttpClient.execute can I still write onto the entity?
And once I am done with it call HttpEntity.consumeContent(). Is that the way
it should work?

Thanks
N




On Tue, Sep 21, 2010 at 3:44 AM, sebb <se...@gmail.com> wrote:

>  On 21 September 2010 10:36, nitin singh <xm...@gmail.com> wrote:
> > Hi,
> > I am trying to stream real time audio data (usual length will be < 30
> > seconds) using http chunking. Specifially, the client will do a Post
> request
> > with TransferEncoding set as chunked in http 1.1.
> > - I have a thread which reads data from the codec and puts it into a
> shared
> > buffer.
> > - Another thread will read the data from the shared buffer and writes it
> in
> > the http chunk.
> > I have successfully done above using Java HttpUrlConnection class.
> However,
> > now we need to do above using https and I started looking at the
> HttpClient
> > classes. I have read all the documentation etc but am not clear how in
> real
> > time I can send data. Specifically,
> > - RequestEntity should not be buffered and cannot be repeatable. Also.
> > RequestEntity.getContentLength is not known.
> > - HttpClient.Execute looks a synchronous call  which writes data all at
> one.
> > It does not help since I write data only when its available.
> >
> > Has anyone done this before using HttpClient?
>
> http://hc.apache.org/httpcomponents-client-ga/examples.html
> and
>
> http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/client/ClientChunkEncodedPost.java
>
> > Thanks in advance!
> > N
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>
>

Re: sending/streaming audio data using chunked encoding

Posted by sebb <se...@gmail.com>.
On 21 September 2010 10:36, nitin singh <xm...@gmail.com> wrote:
> Hi,
> I am trying to stream real time audio data (usual length will be < 30
> seconds) using http chunking. Specifially, the client will do a Post request
> with TransferEncoding set as chunked in http 1.1.
> - I have a thread which reads data from the codec and puts it into a shared
> buffer.
> - Another thread will read the data from the shared buffer and writes it in
> the http chunk.
> I have successfully done above using Java HttpUrlConnection class. However,
> now we need to do above using https and I started looking at the HttpClient
> classes. I have read all the documentation etc but am not clear how in real
> time I can send data. Specifically,
> - RequestEntity should not be buffered and cannot be repeatable. Also.
> RequestEntity.getContentLength is not known.
> - HttpClient.Execute looks a synchronous call  which writes data all at one.
> It does not help since I write data only when its available.
>
> Has anyone done this before using HttpClient?

http://hc.apache.org/httpcomponents-client-ga/examples.html
and
http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/client/ClientChunkEncodedPost.java

> Thanks in advance!
> N
>

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org