Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

java.net.ConnectException: Connection refused: connect

807597Feb 21 2005 — edited Oct 3 2008
I have a problem with URL in Java.

here is my program which i found in the Java Tutorial on Networking basics:
import java.io.*;
import java.net.*;


public class UrlRead
{


public static void main(String[] args) throws Exception
{

URL aURL = new URL("http:/www.yahoo.com/");

BufferedReader in = new BufferedReader(new InputStreamReader(aURL.openStream()));

String str;

while((str=in.readLine())!= null)
System.out.println(str);

in.close();
}



}


It compiles fine, but when i run it it gives me the following error:
Exception in thread "main" java.net.ConnectException: Connection refused: connec
t
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:171)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:158)
at java.net.Socket.connect(Socket.java:426)
at java.net.Socket.connect(Socket.java:376)
at sun.net.NetworkClient.doConnect(NetworkClient.java:139)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:386)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:602)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:303)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:264)
at sun.net.www.http.HttpClient.New(HttpClient.java:336)
at sun.net.www.http.HttpClient.New(HttpClient.java:317)
at sun.net.www.http.HttpClient.New(HttpClient.java:312)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConne
ction.java:481)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection
.java:472)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLCon
nection.java:574)
at java.net.URL.openStream(URL.java:960)
at UrlRead.main(UrlRead.java:14)



In the tutorial it sez:
Platform-Specific Details: Setting the Proxy Host
You can set the proxy host through the command line. Depending on your network configuration, you might also need to set the proxy port. If necessary, ask your system administrator for the name of the proxy host on your network.
UNIX
java -Dhttp.proxyHost=proxyhost
[-Dhttp.proxyPort=portNumber] URLReader

DOS shell (Windows 95/NT)
java -Dhttp.proxyHost=proxyhost
[-Dhttp.proxyPort=portNumber] URLReader

so, i tried the following :

java -Dhttp.proxyHost=10.236.133.78 UrlRead

but it didnt work ; I also tried using portnumber =80....

still the same error.....

Can anyone , please help me out here?

Comments

807597
Connection refused means you connected to a server (the proxy server) but there was no server listening on the port you used.
Check you have the right host and port number.
797177
Unless it's a type your URL is malformed. You have only one forward slash after the protocol and colon. You've written:

http:/www.yahoo.com/
versus
http://www.yahoo.com/
797177
Of course I meant to use the word typo instead of type. Damn fingers! :->
807598
And TBL admits the double slash was a design mistake
807598
i have the same problem

i want to read from URL ("http://www.yahoo.com/") but everytime i try there comes this Exception:
java.net.ConnectException: Connection refused: connect

i have read that it this tries to do this on port 25
http://www.desknow.com/kb/idx/0/027/article/
but this port is blocked. can i do this on another port or can someone help me?

mfg
EJP
The article is talking about a product called DeskNow which apparently talks SMTP over port 25. You are talking HTTP which by default goes over port 80. So the article and port 25 have nothing to do with your problem, which is one of the possibilities mentioned above. It works for me in Java so I suggest it's a firewall or proxy problem at your end.
807598
but what should i do, firewall is disabled and is still says that i still can't open a connection.

has anybody a idea what i can do or what i should test?
807599
Check your firewall setting with network administrator. Very possibly because of that.
807599
Check your firewall setting with network
administrator. Very possibly because of that.
check the date on what you've just replied to. I really hope they haven't just been sat waiting all that time
807600
Hi ,

Try some intr*A*net URL instead of internet URL like yahoo.com .

This will help you to check whether it is indeed firewall problem or someother problem without talking to ur Network administrator .

Regards
San
EJP
Good grief
843785
1st check you data base is up and running.
2nd check firewall
that's the only thing need to worry i believe.
843785
I am having one doubt: can this zombie rack up 1 lakh view, also?
791266
BigDaddyLoveHandles wrote:
I am having one doubt: can this zombie rack up 1 lakh view, also?
Yes, but not that many posts.

I'm locking this zombie thread.
1 - 14
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Oct 31 2008
Added on Feb 21 2005
14 comments
1,296 views