Exception in thread "main" java.net.ConnectException: Connection timed out: connect

I try to run the following code.

import java.net.URL;
import java.io.*;
import javax.net.ssl.HttpsURLConnection;

public class Deneme
{
  public static void main(String[] args)
  throws Exception
  {
    String httpsURL = "https://registration.boun.edu.tr/";
    URL myurl = new URL(httpsURL);
    HttpsURLConnection con = (HttpsURLConnection)myurl.openConnection();
    con.setConnectTimeout(10000000);
    InputStream ins = con.getInputStream();
    InputStreamReader isr=new InputStreamReader(ins);
    BufferedReader in =new BufferedReader(isr);
    String inputLine;
    while ((inputLine = in.readLine()) != null)
        System.out.println(inputLine);
    in.close();
  }
}

But it returns following exception message:

Exception in thread "main" java.net.ConnectException: Connection timed out: connect
      at java.net.PlainSocketImpl.socketConnect(Native Method)
      at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
      at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
      at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
      at java.net.Socket.connect(Socket.java:507)
      at sun.net.NetworkClient.doConnect(NetworkClient.java:152)
      at sun.net.www.http.HttpClient.openServer(HttpClient.java:365)
      at sun.net.www.http.HttpClient.openServer(HttpClient.java:477)
      at sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:278)
      at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:335)
      at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:176)
      at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:744)
      at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:162)
      at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:913)
      at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:234)
      at testClient.Deneme.main(Deneme.java:16)
canistAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

 
colr__Commented:
You are connecting to the server and waiting for a response without actually asking for anything.

For example, your coneting to https://registration.boun.edu.tr/, but you ned to write to the connetion to request a particular document, which you arent doing at the moment.

Try changing the URL to include the filename your trying to donwload.

colr__
0

Experts Exchange Solution brought to you by ConnectWise

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
 
Mayank SAssociate Director - Product EngineeringCommented:
>> con.setConnectTimeout(10000000);

Should perhaps be done before the call to openConnection ()
0
 
mindwalkrCommented:
Are you in a corporate behind a firewall or something ?

Seems to me that you to specify  a proxy.
Take a look here: http://www.javaworld.com/javaworld/javatips/jw-javatip42.html
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
KantiCommented:
Is there a method  setConnectTimeout(10000000);  in HttpsURLConnection
0
 
colr__Commented:
Some input from the poster would be helful.

colr__
0
 
Mayank SAssociate Director - Product EngineeringCommented:
>> Is there a method  setConnectTimeout(10000000);  in HttpsURLConnection

Its there in Java 5, in URLConnection itself:

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

I was wrong in saying that it should be called before the openConnection () because before openConnection () you won't have the handle 'con' initialized.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.