Hi=2C
=20
Trying something which involves catching the "Connection reset by peer" Soc=
ketException. Below is the code snippet from my servlet with explanatory co=
mments.
Does anyone have any idea as to what is happening?
=20
try
{
byte [] bytes =3D getContentBytes()=3B //read the actual bytes of the cont=
ent into an array.
resp.addHeader("Content-Disposition"=2C "attachment=3Bfilename=3Dsomefile.=
zip")=3B
resp.addHeader("Content-Type"=2C "application/zip")=3B
resp.addHeader("Pragma"=2C "no-cache")=3B
resp.addHeader("Connection"=2C "close")=3B
resp.setContentLength(bytes.length)=3B
OutputStream os =3D resp.getOutputStream()=3B
for (int i =3D 0=3B i < bytes.length=3B i++)
{
System.out.println("writing byte " + i)=3B
os.write(bytes[i])=3B
/* 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 =3D=3D bytes.length - 2)
{
System.out.println("doing intermediate flush...")=3B
resp.flushBuffer()=3B
/* 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)=3B
}
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()=3B
=20
/* Voila !!! no exceptions till here and the code exits cleanly !!! */
}
catch (Throwable th)
{
th.printStackTrace()=3B
}
=
|