tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Debashis Roy <r_debas...@hotmail.com>
Subject Who ate my "Connection reset by peer" SocketException?
Date Thu, 04 Aug 2011 10:16:18 GMT

Hi,
 
Trying something which involves catching the "Connection reset by peer" SocketException. Below
is the code snippet from my servlet with explanatory comments.
Does anyone have any idea as to what is happening?
 
try
{
 byte [] bytes = getContentBytes(); //read the actual bytes of the content into an array.
 resp.addHeader("Content-Disposition", "attachment;filename=somefile.zip");
 resp.addHeader("Content-Type", "application/zip");
 resp.addHeader("Pragma", "no-cache");
 resp.addHeader("Connection", "close");
 resp.setContentLength(bytes.length);
 OutputStream os = resp.getOutputStream();
 for (int i = 0; i < bytes.length; i++)
 {
  System.out.println("writing byte " + i);
  os.write(bytes[i]);
  /* write all bytes but the last one to the ostream */
  /* the file save dialog shows up in the browser */
  /* netstat shows an established connection from browser to 8080 of tomcat host */
  if (i == bytes.length - 2)
  {
   System.out.println("doing intermediate flush...");
   resp.flushBuffer();
   /* sleep for 30 secs */
   /* during this time close the browser and click cancel on the file save dialog*/
   /* netstat shows zero connections with port 8080 of tomcat */
   try
   {
    Thread.sleep(30000);
   }
   catch (InterruptedException interex)
   {
   }
  }
  /* the last byte gets written after the sleep period */
  /* was expecting to see the "connection reset by peer" exception here */
 }
 /* or here */
 resp.flushBuffer();
 
 /* Voila !!! no exceptions till here and the code exits cleanly !!! */
}
catch (Throwable th)
{
 th.printStackTrace();
}
 		 	   		  
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message