0

I am getting SocketException on following line. I have something like

    try{
        while(){
            doc = Jsoup.connect("http://ampletrails.com").timeout(300000).get();
        } 
    } catch (Exception e) {
e.printStackTrace();
}

Java exception is thrown and program exit. How can I prevent this to continue in while loop and prevent program to exit.

java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(SocketInputStream.java:185)
    at java.io.BufferedInputStream.fill(BufferedInputStream.java:235)
    at java.io.BufferedInputStream.read1(BufferedInputStream.java:275)
    at java.io.BufferedInputStream.read(BufferedInputStream.java:334)
    at sun.net.www.MeteredStream.read(MeteredStream.java:134)
    at java.io.FilterInputStream.read(FilterInputStream.java:133)
    at sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.read(HttpURLConnection.java:2582)
    at java.io.BufferedInputStream.read1(BufferedInputStream.java:273)
    at java.io.BufferedInputStream.read(BufferedInputStream.java:334)
    at java.io.FilterInputStream.read(FilterInputStream.java:107)
    at org.jsoup.helper.DataUtil.readToByteBuffer(DataUtil.java:113)
    at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:447)
    at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:393)
    at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:159)
    at org.jsoup.helper.HttpConnection.get(HttpConnection.java:148)
    at base_class.main(base_class.java:20)
2
  • This answer might apply, please take a look. Commented May 4, 2014 at 4:08
  • How can I prevent termination of this program? Commented May 4, 2014 at 4:15

1 Answer 1

0

The exception means that the server is sending a TCP reset to terminate the connection you are making.

If this is an intermittent connection, you could avoid a program exit by putting the try and catch blocks inside the while loop instead of outside. It would be best to figure out why the server is resetting your connections, though.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.