users@grizzly.java.net

Re: Flushing output in http server

From: Jeanfrancois Arcand <Jeanfrancois.Arcand_at_Sun.COM>
Date: Thu, 22 May 2008 16:40:42 -0400

Salut,

Peter Speck wrote:
> Hi,
>
> I'm trying to flush the generated html to the client in a lengthy
> processing loop, e.g.
>
> response.setHeader("abc", "def");
> response.setHeader("ghi", "jki");
> response.sendHeaders();
>
> ByteChunk chunk = new ByteChunk();
> while (notDone) {
> do_something_that_takes_long_time();
> chunk.setBytes(...);
> response.doWrite(chunk);
> }
> response.finish();
>
>
> It seems like the response is not sent to the client until I call
> response.finish(). How can I get Grizzly to send the partial content in
> response.doWrite()? As the content-length is not known in advance,
> I've not called response.setContentLength(). I'm using Grizzly 1.7.3.3

Grizzly buffer the bytes before flushing them to avoid unnecessary
network operations. To achieve what you need, just do the following
after the doWrite:

response.action(ActionCode.ACTION_CLIENT_FLUSH,response);

or you might define a very small output buffer so Grizzly will never
buffer the data:

SelectorThread.setMaxHttpHeaderSize(10);

(OK the implementation is quite ugly...under the hood the value passed
will be multiplied by 16). So put a number below 100. Note to me: Need
to fix this 1.0 only value!!

Let me know what you are getting :-)

-- Jeanfrancois




>
>
> Thanks in advance,
> - Peter Speck
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_grizzly.dev.java.net
> For additional commands, e-mail: users-help_at_grizzly.dev.java.net
>