Dear All:
How do I set the timeout for an HttpURLConnection running from a server? i.e. if it did not get the response back in stipulated time, drop the connection?
This is my server connection code, look for a FIXME note. I found lots of notes about the Servlet utilities for this, but little about the server-based URL connections.
Thanks!
Greg
//begin open URL
URL url = new URL(urlString);
conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod(POST);
conn.setAllowUserInteraction(false); // you may not ask the user
conn.setDoOutput(true); // we want to send things
conn.setDoInput(true); // we want recieve things
conn.setUseCaches(false); // turn off caching
//the Content-type should be default, but we set it anyway
conn.setRequestProperty("Content-type", "application/x-www-form-urlencoded");
//fixes Netscap bug?? Do we need this?
//conn.setRequestProperty("User-Agent","Mozilla/4.7 [en] (Win98; I)");
//the content-length should not be necessary, but we're cautious
conn.setRequestProperty("Content-length", Integer.toString(body.length()));
OutputStream rawOutStream = conn.getOutputStream();
out = new DataOutputStream(rawOutStream);
out.writeBytes(body);
out.flush();
out.close();
// get the input stream for reading the reply
// IMPORTANT! Your body will not get transmitted if you get the
// InputStream before completely writing out your output first!
//FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! put some type of the timeout code here!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!?
InputStream rawInStream = conn.getInputStream();
in = new BufferedReader(new InputStreamReader(rawInStream));
String inputLine;
while ((inputLine = in.readLine()) != null)
responseMessage.append(inputLine);
in.close();
____________________________________________________To change your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm
Be respectful! Clean up your posts before replying
____________________________________________________
