Some nwbie question - how to integrate Netty into WebApp

Frederic Bregier fredbregier at free.fr
Fri Sep 11 18:29:48 EDT 2009


Hi,

To send a response in Http, you have two modes, chunked (one message split
in several pieces) and not chunked (1 piece only). The difference must be
set in the first header (Transfer-Encoding to chunked or not present).

So if you want to send by chunk, you have to create the first response with
the TransferEncoding set in the header to chunked and with no data in the
body (no channelBuffer attached to the first response).
You then write this answer to the connected channel.

Then you can send as many chunks as you want by creating each time your own
HttpChunk (DefaultHttpChunk) setting the next ChannelBuffer each time.
Again, write all HttpChunk to the connected channel.

The last written chunk must be an empty one (ChannelBuffer is an empty one,
not null).

Then after the last chunk, you can close the connection if you want.

If possible, the first response should contains a Content-Length header
value (if known).

HTH,
Frederic


olekg wrote:
> 
> Hello,
> 
> I modified the http snoop example but cannot get the functionality of
> Comet/Streaming as on Tomcat. I think I need the following :
> 
> How to send subsequent chunked data one by one without ending the response
> ?
> 
> In http snoop sample we have :
> 
> a) Filling of "responseContent" object with complete response data,
> b) ChannelBuffer created :
> ChannelBuffer buf =
> ChannelBuffers.copiedBuffer(responseContent.toString(), "UTF-8");
> 
> c) Sending of the COMPLETE response :
> HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1,
> HttpResponseStatus.OK);
> response.setContent(buf);
> [...]
> ChannelFuture future = e.getChannel().write(response);
> 
> d) Closing the connection
> future.addListener(ChannelFutureListener.CLOSE);
> 
> 
> I think I need some different approach to write any number of chunks
> without closing the connection.
> 
> Maybe somebody would be able provide mi with some tip ?
> 
> 1. How to create and send chunks ?
> 2. How to have the connection still open ? (In Tomcat NIO handler provides
> us with this functionality).
> 
> regards Olek
> 


-----
Hardware/Software Architect
-- 
View this message in context: http://n2.nabble.com/Some-nwbie-question-how-to-integrate-Netty-into-WebApp-tp3617235p3628822.html
Sent from the Netty User Group mailing list archive at Nabble.com.


More information about the netty-users mailing list