Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java.net.ConnectException: Connection refused:

 
Alejandro Barrero
Ranch Hand
Posts: 335
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
mohammed zubedi
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 89
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One eays way to check if port is really open is to execute "telnet your-host 25" on command line.
 
Alejandro Barrero
Ranch Hand
Posts: 335
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 335
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 89
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My code fails


How exactly does it fail?
 
Alejandro Barrero
Ranch Hand
Posts: 335
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 89
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 107
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Alejandro Barrero
Ranch Hand
Posts: 335
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic