Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

URLConnection timeout..

Options
  • 17-12-2004 8:54pm
    #1
    Registered Users Posts: 463 ✭✭


    I'm writing a program to check validity of URL links in Java atm. When testing the program it reguaraly gets stuck for long periods checking servers that have no response.. neither 200 nor 404, i.e., non existant servers, before timing out.
    I understand there is a method called setConnectTimeout(time) that I can use that takes an int, where time is, being the timeout figure. Can't get it working tho.. mainly because I don't know what to do with it ;-)

    http://java.sun.com/j2se/1.5.0/docs/api/java/net/URLConnection.html#setConnectTimeout(int)

    Any help greatly appreciated!
    ________________________________________________________
    H:\Networks>javac SimpleURLCheck.java
    SimpleURLCheck.java:92: cannot resolve symbol
    symbol : method setConnectTimeout (int)
    location: class SimpleURLCheck
    setConnectTimeout(10);
    ^
    1 error

    --take 2:

    H:\Networks>javac SimpleURLCheck.java
    SimpleURLCheck.java:92: cannot resolve symbol
    symbol : method setConnectTimeout (int)
    location: class java.net.URLConnection
    connection.setConnectTimeout(10);
    ^
    1 error

    --take 3

    H:\Networks>javac SimpleURLCheck.java
    SimpleURLCheck.java:92: cannot resolve symbol
    symbol : method setConnectTimeout (int)
    location: class java.net.URLConnection
    URLConnection.setConnectTimeout(10);
    ^
    1 error
    _________________________________________________________
    Bellow is a small snippet of the URLConnection part of my code..

    URLConnection connection = if (connection instanceof HttpURLConnection)
    {
    HttpURLConnection httpConnection =
    (HttpURLConnection)connection;
    httpConnection.connect();
    String answer = null;
    int response =
    httpConnection.getResponseCode();
    if (response == 200)//else catch error displays
    {
    <snip>
    }
    if(response == 404)
    {
    }


Comments

  • Registered Users Posts: 1,068 ✭✭✭Magic Monkey


    Seeing as the method throws an exception, put it in a try/catch block.


  • Closed Accounts Posts: 41 the_funkyguy


    in the API there a section called "since", shows when the meathod first came to be. in your link it shows 1.5.0, so..... that meathod only works on java 1.5.0!!!!!

    DCU runs 1.4.2, hence it won't work. gonna have to wait like the rest of us :D

    good luck!
    :p:p:p


  • Registered Users Posts: 463 ✭✭Emerson


    in the API there a section called "since", shows when the meathod first came to be. in your link it shows 1.5.0, so..... that meathod only works on java 1.5.0!!!!!

    DCU runs 1.4.2, hence it won't work. gonna have to wait like the rest of us :D

    good luck!
    :p:p:p
    Anyone know of an alternative connection timeout method then for v1.4.2?

    Otherwise I'll have to wait, yea ;P

    thanks


  • Registered Users Posts: 27,163 ✭✭✭✭GreeBo


    You are pretty much screwed Im afraid. Unless you want to write your own URLConnection.
    Is there any real reason that you cant move to 1.5?


  • Registered Users Posts: 139 ✭✭soiaf


    Have a look at the Jakarta Commons component - HttpClient

    http://jakarta.apache.org/commons/httpclient/

    Its API is detailed here:

    http://jakarta.apache.org/commons/httpclient/3.0/apidocs/index.html

    Sounds like you might be interested in (something like) the setSoTimeout method.


  • Advertisement
Advertisement