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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

URLConnection timeout..

  • 17-12-2004 7:54pm
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 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, Registered Users 2 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, Registered Users 2 Posts: 27,366 ✭✭✭✭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, Registered Users 2 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