GeeCON Prague 2014*
The moose likes Sockets and Internet Protocols and the fly likes java.net.ConnectException: Connection refused: Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "java.net.ConnectException: Connection refused:" Watch "java.net.ConnectException: Connection refused:" New topic
Author

java.net.ConnectException: Connection refused:

Alejandro Barrero
Ranch Hand

Joined: Aug 01, 2005
Posts: 319
My code fails:

I can ping to aValidHostName and I, I am not using a firewall and enabled port 25 in Windows. Could there be anything else blocking the port?

Please help,

Alejandro Barrero


Your help will be greatly appreciated,
Alejandro Barrero
mohammed zubedi
Greenhorn

Joined: Jun 04, 2008
Posts: 9
Start your server socket on different port number and try again and secondly pass IP address of your server rather then just name and check.

Socket s = new Socket("127.0.0.1",55);

and check out if problem still exist then send your client and server code.

Thanks
Mohammed Zubedi
Vilmantas Baranauskas
Ranch Hand

Joined: Dec 20, 2006
Posts: 89
One eays way to check if port is really open is to execute "telnet your-host 25" on command line.


Author of <a href="http://www.newsinjector.com" target="_blank" rel="nofollow">NewsInjector</a>
Alejandro Barrero
Ranch Hand

Joined: Aug 01, 2005
Posts: 319
Thanks Mohammed but new Socket("68.87.64.146", 25) didn't work. I have tried with other port numbers.

Thanks Vilmantas; good idea but telnet doesn't work on my machine (Vista) and i couldn't find it in C:\Windows\System32.
Alejandro Barrero
Ranch Hand

Joined: Aug 01, 2005
Posts: 319
I got telnet installed on vista as client and as server, but telnet to my computer is not working. I first tried localhost but it didn't work. Then tried telnet 169.254.16.20 25 (I got 169.254.16.20 from ipconfig and I can access tomcat with 169.254.16.20:8888), but it also fails. Plain telnet 169.254.16.20 tries port 23 but fails.
Please help me find out what I am doing wrong.
Vilmantas Baranauskas
Ranch Hand

Joined: Dec 20, 2006
Posts: 89
My code fails


How exactly does it fail?
Alejandro Barrero
Ranch Hand

Joined: Aug 01, 2005
Posts: 319
This is what i get:
C:>telnet 169.254.16.20 25
Connecting To 169.254.16.20...Could not open connection to the host, on port 25: Connect failed.
Vilmantas Baranauskas
Ranch Hand

Joined: Dec 20, 2006
Posts: 89
I meant how this fails?

Socket aTestSocket = new Socket(aValidHostName, 25);


Do you get an exception or is it running fine but you simply cannot connect?
Mohd Fuzail
Ranch Hand

Joined: Feb 20, 2002
Posts: 107
please do a netstat -a -n to see if port no 25 is already in use. Port No 25 is well defined port for SMTP.

Try using port no between 49152 through 65535


Being defeated is often a temporary condition. Giving up is what makes it permanent.
Alejandro Barrero
Ranch Hand

Joined: Aug 01, 2005
Posts: 319
The problem is that I get "java.net.ConnectException: Connection refused: connect" when running the program.
I ran netstat but I don't see port 25; I think the ports are after : in the Foreign Address and Local Address columns.
I have tried with other ports and get the same error. The reason I was interested originally with port 25 is that I was trying to run a Java.Mail program when I got the exception.

I am searching google for "java.net.ConnectException vista" but no results so far.
mohammed zubedi
Greenhorn

Joined: Jun 04, 2008
Posts: 9
Did you start a server? if so on what IP and port?
if you did start a server then are you accepting the connection ie socket.accept() in your server? check out this.
and try to send your code (Client and Server).
Thanks
Mohammed
 
GeeCON Prague 2014
 
subject: java.net.ConnectException: Connection refused: