Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

java.net.ConnectException: Connection refused  RSS feed

 
paresh doshi
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using socket programming. I am able to run the code.

But I get this error.
"java.net.ConnectException: Connection refused"

The above error occurs intermittently. I dont get it always.

Can anyone tell me what is the Issue.

Please help.
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The error you have specified occurs when you try to connect to a port on a machine that is not open.
Typically, on a server machine, you will open a Server socket to listen for client connections.
After this server socket is open, clients can connect to the port (where the server socket is opened).
However, if for some reasons, the server crashes and hence the port gets closed, you will get the Connection refused error.
I am not sure, but i think you will also get this error if there is a firewall on the server machine that disallows client connections on some port. Since, you are getting this error *sometimes*, I *think* this will not be a firewall issue.

If you are on linux, you can do a "netstat -a" to find whether the requested port is open or not.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!