Not quite -- the client and the server are playing a "request-response
game", and
when one of the two suddenly quits in the middle of the game, the other
should
realize this...

I could imagine that once the client stops waiting for the response (i.e.,
the user
hits the cancel button), there is an error on the server when it attempts to
send
response data to the client

(or is this indistinguishable from the response data being lost/bogged down
somewhere on the net? what does the client do when the server attempts to
send
it some response data it has stopped waiting for? does it send a "don't want
your (from my point of view unrequested) data" back the server?)



... and on to an answer (derived from a simple test, so it's not necessarily
comprehensive or true without exception):

ok, tested it, and actually there is an exception thrown when the client has
stopped listening. BUT... that exception isn't thrown within the servlet's
doGet() / doPost(), but rather by the servlet engine afterwards.

Example:

  public void doPost( HttpServletRequest request, HttpServletResponse
response )
    throws ServletException, IOException
  {
    response.setContentType( "text/plain" );
    PrintWriter out = response.getWriter();

    try
    {
      out.write( "Line 1\n\r" );

      // set a breakpoint here and, while the debugger is halted, click on
the
      // browser's STOP/CANCEL button

      out.write( "Line 2" );
      out.flush();
      response.flushBuffer(); // hmm... apparently, the servlet doesn't get
told whether the data that is flushed
                              // is accepted by the client or not
    }
    catch ( Exception e )
    {
      System.err.println( "Exception: " + e.toString() );
    }

    return;
  }

The catch block doesn't get an exception. But after doPost() is left, the
servlet engine (New Atlanta ServletExec Debugger) reports the following:

Responder.run() caught an IOException 1:Connection reset by peer: socket
write error Most likely the user broke the connection by stopping the
browser.

So, an exception is actually thrown, the server does realize that the
client isn't listening any more (it doesn't tell the servlet, though).
But unfortunately we cannot handle it inside the doPost() method.





> -----Original Message-----
> From: Galbreath, Mark [mailto:[EMAIL PROTECTED]]
> Sent: Dienstag, 8. Oktober 2002 12:52
> To: [EMAIL PROTECTED]
> Subject: Re: Clients that disconnect after inovking a servlet
>
>
> Still don't think you guys know what you are talking about.
> You can't do
> this with HTTP!  Think: "request - response."  Aaaahhhh...now
> you're getting
> it!
>
> -----Original Message-----
> From: Michael Peceny [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, October 08, 2002 6:47 AM
>
> If you used the "space writing" method, do not forget to flush
> the output stream -- otherwise, the output data is buffered and
> only sent to the client once the buffer (default 8kB, I think)
> is full.
>
> Note that this is slow, though -- contacting the client every
> few seconds to determine whether they are still waiting for you
> to send data can cost a lot of time (think of the network between
> your server and the client).
>
> Michael
>
>
> > I'd be interested in knowing how this works with HTTP.  Where
> > is your output
> > stream going?
> [...]
> > > is there a way to check if the client has a connection or
> he/she has
> > closed
> > > the connection using the stop button .....
> >
> > Yes. Trying to write to the output stream would return an
> > IOException. I
> > could write a white space in a separate thread every few
> > seconds and if an
> > exception occurs, I stop processing.
>
> ______________________________________________________________
> _____________
> To unsubscribe, send email to [EMAIL PROTECTED] and
> include in the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources:
> http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
>
> ______________________________________________________________
> _____________
> To unsubscribe, send email to [EMAIL PROTECTED] and
> include in the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources:
> http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
>

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to