Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

java.net.ConnectException:

Status
Not open for further replies.

iamsiraj

Programmer
Jan 8, 2003
7
US
Hello,

I am trying to get the http responseMessage/responseCode using the following peace of code (Java.net.* package)
******************************************************
URL url = new URL("HttpURLConnection httpconn=null;
httpconn=(HttpURLConnection)url.openConnection();
int responseCode = httpconnection.getResponseCode();
System.out.println("RestponseCode: " + responseCode);
******************************************************
But i am getting the follwoing connection time out error,So COULD SOME ONE PLEASE ADVICE ME, how to fix this problem

Error Message is:
java.net.ConnectException: Operation timed out: connect at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.PlainSocketImpl.doConnect PlainSocketImpl.java:350)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:137)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:124)
at java.net.Socket.<init>(Socket.java:268)
at java.net.Socket.<init>(Socket.java:95)
 
I have tried the code:

Code:
import java.net.*;

class URLtest
{

 public static void main(String args[])
 {
 	try{
		URL url = new URL(&quot;[URL unfurl="true"]http://www.tek-tips.com&quot;);[/URL]
		HttpURLConnection httpconnection=null;
		httpconnection=(HttpURLConnection)url.openConnection();         
		int responseCode = httpconnection.getResponseCode();
		System.out.println(&quot;RestponseCode: &quot; + responseCode);
	}
	catch(Exception e){
		e.printStackTrace();
	}
 }

}

And it worked fine. You just got a timeout while connecting to the server... I can't really tell you where this comes from. Is the URL you used correct? Is the server behind this URL alive? Can you view a page in your browser or ping it?

Cheers

frag

patrick.metz@epost.de
 
Uuups... forgot to say that I could not test it in the internet. Our firewall here at work won't let me out, so I tried it with a webserver inside the intranet... don't know if this is important.

patrick.metz@epost.de
 
Hi frag,

Thanks for the reply, I had not set the proxy setting; I just came to know a bit late and i added the following stuffs in my code and it works fine for me.
System.getProperties().put( &quot;proxySet&quot;, &quot;true&quot; );
System.getProperties().put( &quot;proxyHost&quot;, &quot; );
System.getProperties().put( &quot;proxyPort&quot;, &quot;8080&quot; );

Thanks
Siraj
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top