I have tried writing to the Response OutputStream, because there is no proper 
disconnect callback. 
Unfortunately, this doesn't seem to work either. When the client is 
disconnected, writing and flushing the buffer did not throw an exception.

I use the following code:

private boolean write(byte[] output, AsyncContext context) {
    try {
        OutputStream stream  = context.getResponse().getOutputStream();
        stream.write(output);
        stream.flush();
        return true;
    } catch (IOException ex) {
        // Disconnect detected
        log.error(ex);
        removeAsyncContext(context); 
        return false;
    }
}

The weird thing is, it does throws an exception the second time you try to 
write to the output stream. 
It looks like the first time you write it flips internal state to error, 
without notifying.

What is a proper way to detect whether something written to the client is 
actually received?

Oscar

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to