Title: RE: [jdjlist] RE: HttpURLConnection timeout

Stan, do you happen to have any code/links for killing the rogue thread?  interrupt() does not seem to work.

Greg

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, October 01, 2002 4:42 PM
To: JDJList
Subject: [jdjlist] RE: HttpURLConnection timeout


I know you can set the timeout on a Socket.  Unfortunately, it doesn't
appear that URLConnection provides access to the underlying socket. :-(
You can always run your code in a thread and have your main thread do a join
for the stipulated time...
 
Stan

-----Original Message-----
From: Greg Nudelman [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, October 01, 2002 4:10 PM
To: JDJList
Subject: [jdjlist] HttpURLConnection timeout



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
____________________________________________________


____________________________________________________
To change your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm

Be respectful! Clean up your posts before replying
____________________________________________________

____________________________________________________
To change your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm

Be respectful! Clean up your posts before replying
____________________________________________________

Reply via email to