Diagnosing Socket Error

R

Roger

Hi

I have a servlet that is writing supposedly valid HTML to the
HttpServletResponse writer. Every once in a while my servlet throws a
java.net.SocketException Connection re-set by peer socket write error
when closing the writer with writer.close(). I assume that I'm writing
rubbish to the writer but I can't work out how to discover what it is
that is triggering the error. I can't try and catch the exception
because the compiler says that the error is not thrown by the
writer.close() method and it's impractical to print out everything
that's getting written as the error only occurs occassionally and I
would be wading through screeds of output. I would be grateful for any
suggestions.

Regards
Roger
 
S

Sudsy

Roger said:
Hi

I have a servlet that is writing supposedly valid HTML to the
HttpServletResponse writer. Every once in a while my servlet throws a
java.net.SocketException Connection re-set by peer socket write error
when closing the writer with writer.close().
<snip>

Perhaps, every once in a while a client is hitting the Esc key in order
to stop loading your page? That would close the socket and give rise to
the behaviour you're seeing. IOW don't worry about it.
 
R

Roger

Sudsy said:
<snip>

Perhaps, every once in a while a client is hitting the Esc key in order
to stop loading your page? That would close the socket and give rise to
the behaviour you're seeing. IOW don't worry about it.

I've tested that, and it looks like you're correct. Is there some way
I can stop the SocketException from printing it's screen dump to the
console - it swamps it and removes more important messages.

Regards
Roger
 
S

Sudsy

Roger wrote:
I've tested that, and it looks like you're correct. Is there some way
I can stop the SocketException from printing it's screen dump to the
console - it swamps it and removes more important messages.

A quick dip into the javadocs (your best friend!) shows that the
methods in java.io.Writer (PrintWriter extends it) can throw an
IOException. Now java.net.SocketException extends IOException.
Since you've got access to the servlet source, you could do
something like this:

try {
PrintWriter pw = resp.getWriter();
pw.println( ... );
...
pw.flush();
pw.close();
}
catch( SocketException e ) {
}
catch( Exception e ) {
// log as usual
}

IOW ignore the socket exceptions.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top