• Post Reply Bookmark Topic Watch Topic
  • New Topic

ConnectException when I try to use my local host(127.0.0.1)  RSS feed

 
Angel Ortiz
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey! I was trying to run to classes I got from a book to start learning about servers and clients on java. The problem is that when I run the program I get an exception like this: java.net.ConnectException: Connection refused. I don't understand why that happens since I'm using my local host 127.0.0.1 and port 5000. I've also tried to use different ports but it didn't work. I'm using OS X 10.11.6 so I don't know if that has anything to do with this. Thanks in advance!

Server Class


Client Class
 
Forest White
Greenhorn
Posts: 8
Netbeans IDE Python VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good afternoon,

There are a number of reasons which could lead to this specific exception. From your description, I cannot definitively tell, but you could try:

* Make sure you start your server first - it is helpful to output a console message when the server is waiting for a client connection e.g.
* Then start your client.
* Use "localhost" instead of "127.0.0.1" in your client program.
* From the command line, ping 127.0.0.1 to make sure the loopback address is operating as expected (no firewall in the way)
 
Angel Ortiz
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for the tip about printing something to know whether the server was working, it made me realize that the two classes were not running simultaneously. Do you know how to do that on the mac terminal? Because I managed to made them work but I had to run the server on the terminal and the client on Eclipse.
 
Henry Wong
author
Sheriff
Posts: 23280
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, MACs run a version of Unix. So, you can run the server in a terminal. Background the process. Then run the client in the terminal.

Or since it is more easier to control, open two terminals -- one for the server and one for the client.

Henry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!