Skip to content
Advertisement

java.net.ConnectException: Connection refused

I’m trying to implement a TCP connection, everything works fine from the server’s side but when I run the client program (from client computer) I get the following error:

JavaScript

I tried changing the socket number in case it was in use but to no avail, does anyone know what is causing this error & how to fix it.

The Server Code:

JavaScript

The Client Code:

JavaScript

Advertisement

Answer

This exception means that there is no service listening on the IP/port you are trying to connect to:

  • You are trying to connect to the wrong IP/Host or port.
  • You have not started your server.
  • Your server is not listening for connections.
  • On Windows servers, the listen backlog queue is full.
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement