How to resolve the java.net.ConnectException in Java?

0 votes
I am trying to establish a TCP connection, but I am getting java.net.ConnectionException. How to resolve it?
Jun 4, 2018 in Java by Daisy
• 8,050 points
152 views

1 answer to this question.

0 votes

If you are getting java.net.ConnectionException, it means no port is listening your request.Following are the condition which will give this exception.

  • You are trying to connect wrong port.
  • You have not started your server.
  • Your server is not listening to the request.

Before running the server:

  • You should check the port number and host name.
  • There should not be any firewall, which will restrict the connection.
answered Jun 4, 2018 by Akrati
• 3,150 points

Related Questions In Java

0 votes
1 answer

How to print java array in the simplest way?

String[] arr = new String[] {"John", "Mary", ...READ MORE

answered Apr 17, 2018 in Java by sophia
• 1,400 points
73 views
0 votes
1 answer

How to calculate the difference between two date instances in Java?

You can use Joda Time Library. Interval i ...READ MORE

answered May 4, 2018 in Java by parth295
• 4,620 points
55 views
0 votes
2 answers

How to clear the console in Java?

import java.io.IOException; public class CLS { ...READ MORE

answered Aug 27, 2018 in Java by Sushmita
• 6,880 points
4,803 views
0 votes
2 answers

How can we add leading zeros to the number in Java?

From Java 1.5 you can use the String.format method. ...READ MORE

answered Aug 26 in Java by Sirajul
• 25,700 points
246 views
0 votes
1 answer

How do I fix a NullPointerException?

When you declare a reference variable (i.e. ...READ MORE

answered Apr 13, 2018 in Java by parth295
• 4,620 points
86 views
0 votes
2 answers

Does the finally block always execute in Java?

public static void main(String[] args) { ...READ MORE

answered Aug 8, 2018 in Java by Sushmita
• 6,880 points
264 views
0 votes
1 answer

What is ArrayIndexOutOfBoundsException ?

If You check System.out.print(names.length); you will get 3 ...READ MORE

answered May 11, 2018 in Java by sharth
• 3,320 points
73 views
0 votes
1 answer

How can we resolve ClassNotFoundException in Java?

Your classpath is broken. Depending on how you ...READ MORE

answered May 22, 2018 in Java by Akrati
• 3,150 points
61 views
0 votes
2 answers

How to break the nested loop in Java?

You can use break with a label for the ...READ MORE

answered Sep 20, 2018 in Java by Sushmita
• 6,880 points
87 views
0 votes
1 answer

How to read text files from the Classpath in Java?

InputStream in = this.getClass().getClassLoader().getResourceAsStream("TextFile.txt"); InputStream in = this.getClass().getResourceAsStream("/TextFile.txt"); package ...READ MORE

answered May 8, 2018 in Java by Akrati
• 3,150 points
240 views