users@glassfish.java.net

reading from client when using asynchronous CometWriter

From: <glassfish_at_javadesktop.org>
Date: Thu, 30 Sep 2010 08:15:36 PDT

Using Comet for our communication, we have issues when reading data on the client.

On the server we use registerAsyncWrite(handler) and then a CometWriter in order to have asynchronous writes.

However: the data on the client comes in as a chuncked http stream.

The client uses a regular java.net.URLConnection. Reading the bytes from the inputstream shows the chunk length + CRLF + the data + 7 bytes to mark the end of the chunk, while I would expect those chunks to be handled by the HttpUrlConnection.

I suspect that the headers (especially Transfer-Encoding: chunked) are not written back to the client. When we call response.flushBuffer() in the server code, the headers are written, and then the HttpUrlConnection reads the data from the stream as expected. Flushing however, does not "solve" the problem because after one write, the connection will close.

The question is why the connection closes when we call response.flushBuffer()?
[Message sent by forum member 'tiainen']

http://forums.java.net/jive/thread.jspa?messageID=484038