java - Applet HttpUrlConnection Chunked Response problem -
I have an HTTP protocol with an IIS 6.0 server applet. I server response data discarded, but sometimes (some browsers ) I have a problem pasting the server's answer in a few buffers, and when the server closes the connection through timeout then it reaches me.
url = new URL (urlStr); Hook = (HttpURL connection) url.openConnection (); Huc.setDefaultUseCaches (wrong); Huc.setAllowUserInteraction (true); Huc.setDoInput (true); Huc.setUseCaches (wrong); Huc.setRequestProperty ("Pagera", "No-Cash"); Huc.setRequestProperty ("cache-control", "no-cache"); Huc.setRequestProperty ("Finished", "-1"); Huc.setRequestProperty ("content type", "text / html"); InputStream = huc.getInputStream (); ... while (TrunkStop) {while (errorConnection & amp; trunkStop) {connectToServer (); If (errorConnection) {sleepThread (); }} While (! Error connection and trunktop) {readData (); } ...} ... zero read data () {if (trunkStop) {return; } Try {ReadLine (); AddTask (); // put in the work queue} catch (exception e) {getLogger () Logs (level warning, "error connection ..."); }} ... string readline () throws IOException, is interrupted Exception {sb = new StringBuilder (); Int prev = -1; While (! Error Connection & Trunktop) is {read = is.read (); If (read == -1) {if (System.currentTimeMillis () - Timer> 150000) {getLogger () Log (level .SEEEE, "reconnect by timeout"); ErrorConnection = True; } Thread. Sleep (10); to continue; } Else if (read == 13) {} else if (read == 10 & amp; amp; and = = 13) {break; } Other {sb.append (read four)); System.out.print ((four) read); } Prev = Reading; Timer = system syentime milliseconds (); } Return sb.toString (); }
Some browser buffers, I do not know at this moment IIS already responds, this is the client problem, IE7, Java 1.6.0_16
idea?
when read == - 1
(which means that readLine ()
You are waiting for 150 seconds before setting the "ErrorConnection = true" , which is readLine
and later readData
and (Error Connection & Trunkstop) {readData ();} To prevent
.
This is the connection time of 150 seconds IIS server You can be more.
Btw You can use logical and operator instead of bit-wise and operator ( & amp; Are you using r (
& amp;
)? Are you sure what you want? Check the difference.
Comments
Post a Comment