Diagnosing Socket Error

Discussion in 'Java' started by Roger, Jun 14, 2004.

  1. Roger

    Roger Guest

    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
    Roger, Jun 14, 2004
    #1
    1. Advertising

  2. Roger

    Sudsy Guest

    Roger wrote:
    > 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.
    Sudsy, Jun 14, 2004
    #2
    1. Advertising

  3. Roger

    Roger Guest

    Sudsy <> wrote in message news:<>...
    > Roger wrote:
    > > 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.


    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
    Roger, Jun 15, 2004
    #3
  4. Roger

    Sudsy Guest

    Roger wrote:
    <snip>
    > 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.
    Sudsy, Jun 15, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. andy6 via DotNetMonster.com
    Replies:
    0
    Views:
    678
    andy6 via DotNetMonster.com
    Sep 8, 2006
  2. Laszlo Nagy
    Replies:
    1
    Views:
    4,755
    Mark Wooding
    Jan 27, 2009
  3. Dave Thacker
    Replies:
    1
    Views:
    109
    Matthew Harris
    Dec 22, 2007
  4. DrKen
    Replies:
    8
    Views:
    533
    John G Harris
    Nov 30, 2011
  5. loial
    Replies:
    5
    Views:
    188
    Grant Edwards
    May 22, 2013
Loading...

Share This Page