You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Ming Deng <mi...@gmail.com> on 2008/09/27 23:13:55 UTC
How can Servlet detect lost of connection to client?
If a client HTTP request takes some time to process on the servlet side, it
is possible that the Tomcat can lose connection to the client in the middle
of this processing time, due to various reasons, for example the client
quit. How can servlet detect such event so it can terminate the server side
processing which is not needed any more?
thanks,
Ming
Re: How can Servlet detect lost of connection to client?
Posted by André Warnier <aw...@ice-sa.com>.
If (and only if) it is really worth the effort, there might be a way to
do this.
I would not know the details of how to achieve this with Tomcat, but I
remember writing something like that under Apache and perl.
Consider thus what follows as a very rough approximation, and no more
than an hint.
It would go like this :
At the beginning of your servlet processing, you write the HTTP response
headers to the client, and a first response part saying "please wait...".
Then your servlet starts processing, and at given intermediate points in
this processing, it writes a further "please wait some more..." to the
output.
If when writing it finds a closed socket, it knows the client has gone.
Otherwise, it continues processing and sends the real response at the end.
The above is predicated on my suspicion (nothing sure here), that Tomcat
can/will regularly flush the servlet output to the browser, even before
the servlet output is complete (or that the servlet can itself "flush"
the buffer).
In my case, the purpose was not to save processing time on the server
side. Rather, it was to avoid that the user on the client side would be
faced with a long response time without visual feedback, and would start
clicking all over the place, as users are wont to do.
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
RE: How can Servlet detect lost of connection to client?
Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Edward Dowgiallo [mailto:eddowgiallo@gmail.com]
> Subject: Re: How can Servlet detect lost of connection to client?
>
> How about putting in a lifecycle listener for Session destruction?
A Session typically persists across the coming and going of multiple HTTP connections for a client, so that doesn't sound terribly useful for this purpose.
- Chuck
THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: How can Servlet detect lost of connection to client?
Posted by Edward Dowgiallo <ed...@gmail.com>.
How about putting in a lifecycle listener for Session destruction?
Ed
On Sat, Sep 27, 2008 at 6:14 PM, Martin Gainty <mg...@hotmail.com> wrote:
>
> agreed.. I would definitely try that solution first
>
> also you may want to use a different connector (such as NIOConnector..)
> that supports Events
> if you keep in mind your client's browser will not display anything until
> the entire request is complete. so write a client application for your
> cometProcessor, to test how it works
> details at
> http://people.apache.org/~fhanik/http.html<http://people.apache.org/%7Efhanik/http.html>
>
> a rather elaborate example is located here
>
> http://www.ibm.com/developerworks/websphere/library/techarticles/0809_vamsi/0809_vamsi.html#15.Creating%20an%20NIO%20Connector|outline<http://www.ibm.com/developerworks/websphere/library/techarticles/0809_vamsi/0809_vamsi.html#15.Creating%20an%20NIO%20Connector%7Coutline>
>
> realising the asynchronous event model uses the comet processor
>
> http://tomcat.apache.org/tomcat-6.0-doc/api/org/apache/catalina/CometProcessor.html
>
> a more complete example is available here
>
> http://stackoverflow.com/questions/109294/are-writes-from-within-a-tomcat-6-cometprocessor-non-blocking
>
> filip and bill have been doing the most work on this Processor so i would
> ping them for more information..
>
> Dziekuje
> Martin
> ______________________________________________
> Disclaimer and confidentiality note
> Everything in this e-mail and any attachments relates to the official
> business of Sender. This transmission is of a confidential nature and Sender
> does not endorse distribution to any party other than intended recipient.
> Sender does not necessarily endorse content contained within this
> transmission.
>
>
> > Date: Sat, 27 Sep 2008 23:21:00 +0200
> > From: miki@ceti.pl
> > To: users@tomcat.apache.org
> > Subject: Re: How can Servlet detect lost of connection to client?
> >
> > Ming Deng wrote:
> > > If a client HTTP request takes some time to process on the servlet
> side, it
> > > is possible that the Tomcat can lose connection to the client in the
> middle
> > > of this processing time, due to various reasons, for example the client
> > > quit. How can servlet detect such event so it can terminate the server
> side
> > > processing which is not needed any more
> > I believe that the only way is to receive IOException while writing to
> > respone.
> >
> > --
> > Mikolaj Rydzewski <mi...@ceti.pl>
> >
> >
> > ---------------------------------------------------------------------
> > To start a new topic, e-mail: users@tomcat.apache.org
> > To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> > For additional commands, e-mail: users-help@tomcat.apache.org
> >
>
> _________________________________________________________________
> See how Windows Mobile brings your life together—at home, work, or on the
> go.
> http://clk.atdmt.com/MRT/go/msnnkwxp1020093182mrt/direct/01/
RE: How can Servlet detect lost of connection to client?
Posted by Martin Gainty <mg...@hotmail.com>.
agreed.. I would definitely try that solution first
also you may want to use a different connector (such as NIOConnector..) that supports Events
if you keep in mind your client's browser will not display anything until the entire request is complete. so write a client application for your cometProcessor, to test how it works
details at
http://people.apache.org/~fhanik/http.html
a rather elaborate example is located here
http://www.ibm.com/developerworks/websphere/library/techarticles/0809_vamsi/0809_vamsi.html#15.Creating%20an%20NIO%20Connector|outline
realising the asynchronous event model uses the comet processor
http://tomcat.apache.org/tomcat-6.0-doc/api/org/apache/catalina/CometProcessor.html
a more complete example is available here
http://stackoverflow.com/questions/109294/are-writes-from-within-a-tomcat-6-cometprocessor-non-blocking
filip and bill have been doing the most work on this Processor so i would ping them for more information..
Dziekuje
Martin
______________________________________________
Disclaimer and confidentiality note
Everything in this e-mail and any attachments relates to the official business of Sender. This transmission is of a confidential nature and Sender does not endorse distribution to any party other than intended recipient. Sender does not necessarily endorse content contained within this transmission.
> Date: Sat, 27 Sep 2008 23:21:00 +0200
> From: miki@ceti.pl
> To: users@tomcat.apache.org
> Subject: Re: How can Servlet detect lost of connection to client?
>
> Ming Deng wrote:
> > If a client HTTP request takes some time to process on the servlet side, it
> > is possible that the Tomcat can lose connection to the client in the middle
> > of this processing time, due to various reasons, for example the client
> > quit. How can servlet detect such event so it can terminate the server side
> > processing which is not needed any more
> I believe that the only way is to receive IOException while writing to
> respone.
>
> --
> Mikolaj Rydzewski <mi...@ceti.pl>
>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
_________________________________________________________________
See how Windows Mobile brings your life together—at home, work, or on the go.
http://clk.atdmt.com/MRT/go/msnnkwxp1020093182mrt/direct/01/
Re: How can Servlet detect lost of connection to client?
Posted by Bill Barker <wb...@wilshire.com>.
"Ming Deng" <mi...@gmail.com> wrote in message
news:a79731c20809271424m556610e9n2a761923658fc9e1@mail.gmail.com...
> Even though servlet can't detect that kind of events, will Tomcat be aware
> of such events in its internal process?
>
Generally, no Tomcat won't be aware of such an event until it attempts to
write on the Socket. It doesn't pay attention to the Socket while the
Servlet is processing.
>
>
> On Sat, Sep 27, 2008 at 5:21 PM, Mikolaj Rydzewski <mi...@ceti.pl> wrote:
>
>> Ming Deng wrote:
>>
>>> If a client HTTP request takes some time to process on the servlet side,
>>> it
>>> is possible that the Tomcat can lose connection to the client in the
>>> middle
>>> of this processing time, due to various reasons, for example the client
>>> quit. How can servlet detect such event so it can terminate the server
>>> side
>>> processing which is not needed any more
>>>
>> I believe that the only way is to receive IOException while writing to
>> respone.
>>
>> --
>> Mikolaj Rydzewski <mi...@ceti.pl>
>>
>>
>> ---------------------------------------------------------------------
>> To start a new topic, e-mail: users@tomcat.apache.org
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
>
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: How can Servlet detect lost of connection to client?
Posted by Ming Deng <mi...@gmail.com>.
Even though servlet can't detect that kind of events, will Tomcat be aware
of such events in its internal process?
On Sat, Sep 27, 2008 at 5:21 PM, Mikolaj Rydzewski <mi...@ceti.pl> wrote:
> Ming Deng wrote:
>
>> If a client HTTP request takes some time to process on the servlet side,
>> it
>> is possible that the Tomcat can lose connection to the client in the
>> middle
>> of this processing time, due to various reasons, for example the client
>> quit. How can servlet detect such event so it can terminate the server
>> side
>> processing which is not needed any more
>>
> I believe that the only way is to receive IOException while writing to
> respone.
>
> --
> Mikolaj Rydzewski <mi...@ceti.pl>
>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
Re: How can Servlet detect lost of connection to client?
Posted by Mikolaj Rydzewski <mi...@ceti.pl>.
Ming Deng wrote:
> If a client HTTP request takes some time to process on the servlet side, it
> is possible that the Tomcat can lose connection to the client in the middle
> of this processing time, due to various reasons, for example the client
> quit. How can servlet detect such event so it can terminate the server side
> processing which is not needed any more
I believe that the only way is to receive IOException while writing to
respone.
--
Mikolaj Rydzewski <mi...@ceti.pl>
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org