>My httpServlet makes a "connection reset by peer" error while browser is
>trying to load an html page. This almost always happens but it sometimes
>runs OK. Servlet makes too many jdbc operations and i think that this may
be
>the cause of that error. Here you got the pseudo-code of the servlet:


I used to get the same problem on the client end from an embedded web server
I developed.  Here's what I learned:

1.  It only happened when I was serving up binary files from disk.
2.  The byte[] buffer I was using was either too big or too small.  1024
worked best.
3.  I had problems when using both an OutputStream and a DataOutput stream
together to send data back to the browser.  To solve it, I had to do 2
things.  1) Use OutputStream.print() instead of
DataOutputStream.writeChars() when sending binary data.  2) Always flush
before switching from one stream type to another.

Check out the attached code snippet.  It's got comments that explain it all
inline.  Whenever the browser showed a "Connection reset by peer" message,
it was accompanied by a "Socket write failed" message on the server side.
The changes mentioned above fixed all that.

Make sure also that you set the "Content-Type" header to
"application/octet-stream" when sending binary data.  I don't know if you're
sending binary data (such as graphics) files like I was, but if you are,
then I hope this helps.

Ed



begin 666 binary.txt
M"2\J*@T*"2 J"5-E;F1S(&$@<F5A;"!F:6QE(&9R;VT@=&AE('9I<G1U86P@
M<F]O="!D:7)E8W1O<GDN#0H)("H)0'!A<F%M('!&:6QE('1H92!F:6QE('1O
M('-E;F0N("!4:&4@9FEL96YA;64@:7,@<F5L871I=F4@=&\@=&AE(&-U<G)E
M;G0@9&ER96-T;W)Y+@T*"2 J+PD-"@EP<FEV871E('9O:60@4V5N9$)I;F%R
M>49I;&4H4W1R:6YG('!&:6QE*2!T:')O=W,@24]%>&-E<'1I;VX-"@E[#0H)
M"2\O"5-T86YD87)D(')E<&QY(&AE861E<B!F;W(@8FEN87)Y(&9I;&5S+@T*
M"0E3=')I;F<@<W1R0FEN2&5A9&5R(#T-"@D)"2)(5%10+S$N,2 R,# @3TM<
M<EQN(B K#0H)"0DB4V5R=F5R.B!&;W)M(%!R;V9I;&5R+S,N,%QR7&XB("L-
M"@D)"2)#;VYT96YT+51Y<&4Z(&%P<&QI8V%T:6]N+V]C=&5T+7-T<F5A;5QR
M7&XB("L-"@D)"2)<<EQN(CL-"@D)1FEL92!F(#T@;F5W($9I;&4H<$9I;&4I
M.PT*"0E&:6QE26YP=713=')E86T@9FES(#T@;F5W($9I;&5);G!U=%-T<F5A
M;2AF*3L-"@D)1&%T84EN<'5T4W1R96%M(&1I<R ](&YE=R!$871A26YP=713
M=')E86TH9FES*3L-"@D)1&%T84]U='!U=%-T<F5A;2!D;W,@/2!N97<@1&%T
M84]U='!U=%-T<F5A;2AS;V,N9V5T3W5T<'5T4W1R96%M*"DI.PT*"0DO+PE0
M=6UP(&]U="!T:&4@9FEL92P@,4L@870@82!T:6UE+@T*"0EB>71E6UT@8B ]
M(&YE=R!B>71E6S$P,C1=.PT*"0EI;G0@>" ](# [#0H)"2\O"4U54U0@55-%
M($]3+E!224Y4+"!.3U0@1$]3+E=2251%0TA!4E,H*2X-"@D)+R\)3U1(15)7
M25-%($=205!(24-3(%=)3$P@3D]4(%=/4DLN#0H)"6]S+G!R:6YT*'-T<D)I
M;DAE861E<BD[#0H)"2\O"4%"4T],551%3%D@35535"!&3%532"!(14%$15(@
M3U(@64]5(%=)3$P@1T54#0H)"2\O"2=33T-+150@5U))5$4@1D%)3$5$)R!%
M4E)/4E,@3TX@5$A%("=72$E,12<@3$E.12$-"@D)+R\)04Q705E3($9,55-(
M($)%1D]212!35TE40TA)3D<@1E)/32!/3D4@4U1214%-(%194$4-"@D)+R\)
M5$\@04Y/5$A%4B!/3B!42$4@4T%-12!35%)%04T@*$]3("TM/B!$3U,I(0T*
M"0EO<RYF;'5S:"@I.PT*"0EW:&EL92AT<G5E*0T*"0E[#0H)"0EX(#T@9&ES
M+G)E860H8BD[#0H)"0EI9BAX(#T]("TQ*0T*"0D)"6)R96%K.PT*"0D)9&]S
M+G=R:71E*&(L(# L('@I.PT*"0D)+R\)04)33TQ55$5,62!-55-4($9,55-(
M($]2(%E/52!#04X@1T54#0H)"0DO+PDG4T]#2T54(%=2251%($9!24Q%1"<@
M15)23U)3(%=(14X-"@D)"2\O"5-%3D1)3D<@0DE'($9)3$53+"!354-(($%3
M($1/3B=4(%-43U N054N#0H)"0DO+PE!3%=!65,@1DQ54T@@049415(@159%
M4ED@5U))5$4@24Y3241%($$@3$]/4"$-"@D)"61O<RYF;'5S:"@I.PT*"0E]
M#0H)"61I<RYC;&][EMAIL PROTECTED]*"0ED;W,N9FQU<V@H*3L-"@D)9&]S+F-L;W-E
+*"D["0D-"@E]#0H`
`
end

___________________________________________________________________________
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