I have an Applet with HttpUrlConnection to IIS 6.0 Server. Server response chunked data, but sometimes (some browsers) i have a problem. Server answers stick in certain buffer, and arrive at me when the server close connection by timeout.
url = new URL(urlStr);
huc = (HttpURLConnection) url.openConnection();
huc.setDefaultUseCaches(false);
huc.setAllowUserInteraction(true);
huc.setDoInput(true);
huc.setUseCaches(false);
huc.setRequestProperty("Pragma", "no-cache");
huc.setRequestProperty("Cache-Control", "no-cache");
huc.setRequestProperty("Expires", "-1");
huc.setRequestProperty("Content-type", "text/html");
InputStream is = huc.getInputStream();
...
while (!trunkStop) {
while (errorConnection && !trunkStop) {
connectToServer();
if (errorConnection) {
sleepThread();
}
}
while (!errorConnection && !trunkStop) {
readData();
}
...
}
...
void readData() {
if (trunkStop) {
return;
}
try {
readLine();
addTask();//put to task queue
} catch (Exception e) {
getLogger().log(Level.WARNING, "Error connection...");
}
}
...
String readLine() throws IOException, InterruptedException {
sb = new StringBuilder();
int prev = -1;
while (!errorConnection && !trunkStop) {
read = is.read();
if (read == -1) {
if (System.currentTimeMillis() - timer > 150000) {
getLogger().log(Level.SEVERE, "RECONNECT BY TIMEOUT");
errorConnection = true;
}
Thread.sleep(10);
continue;
} else if (read == 13) {
} else if (read == 10 && prev == 13) {
break;
} else {
sb.append((char) read);
System.out.print((char) read);
}
prev = read;
timer = System.currentTimeMillis();
}
return sb.toString();
}
certain browser buffer, i don't know. At this moment IIS already send answers, this is client problem, IE7, java 1.6.0_16
Any ideas ?