Hello,

I was hoping that someone could give me some help with the following
problem. I have a servlet that needs to respond to requests from
URLs and other servlets. Servlet to servlet link works fine.
The problem is that there does not seem to be a way for a URL
connection
to tell when the servlet connection has gone away, so the URL "client"
will hang forever.

Here is a code snippet from the client that has the URL connection
to the servlet:

HttpURLConnection dataCon = null;
// url_ is the URL to the servlet
dataCon = (HttpURLConnection) url_.openConnection();
// Set up the connection to be POST, allow output, and set the session
// cookie
dataCon.setDoOutput(true);
dataCon.setRequestMethod("POST");
if (sessionCookie_ != null) {
    dataCon.setRequestProperty("Cookie", sessionCookie_);       
}
OutputStream out = dataCon.getOutputStream();
...write the output
out.flush();
out.close();
InputStream in = null;
in = dataCon.getInputStream();
int numBytes = 0;
try
{
do
{
    numBytes = in.available();
    if(numBytes < 1)
    {
      try
      {
        Thread.sleep(1000*2);
      }
      catch(InterruptedException ie)
      {
      }
    }
}while(numBytes<1);
}
catch(IOException ioe)
{
 ...connection gone
 .
 .
 return;
}
...read the input


The in.available() never throws an exception if the web server
times out and breaks the connection.
Is there some way to tell if the servlet/web server has disconnected?
Thanks.


 



=====
Wyn Easton
[EMAIL PROTECTED]

__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - Buy the things you want at great prices. 
http://auctions.yahoo.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]

Reply via email to