go to  ForumEasy.com   
JavaPro
Home » Archive » Message


[Email To Friend][View in Live Context][prev topic « prev post | next post » next topic]
  "Connection refused" vs "Address already in use"
 
Subject: "Connection refused" vs "Address already in use"
Author: EricJ
In response to: java.net.ConnectException: Connection refused: connect
Posted on: 04/13/2007 02:39:42 PM

Unlike "Address already in use" error which is caused by client side settings about maximum port can be mobilized during a certain amount of time, "Connection refused" is caused by server side settings which internationally rejected your connection for some reasons. Most likely, your client application is so aggressive in acquiring connection that the backlog queue of the remote server is full.

It's also interesting to note that "Address already in use" error happened in one thread environment and "Connection refused" error happened within multiple threads environment, even though they both try to open connection by calling the same code:

      try{
          socket = new Socket(addr, PORT);
      }catch(IOException e){
          e.printStackTrace();
          System.exit(-1);
      }


 

> On 04/13/2007 02:09:21 PM EricJ wrote:

How many connections to remote server can an application open concurrently? Let's take a look at the following code:

  String HOST = "myServer";
  int PORT = 1234;
  InetAddress addr = InetAddress.getByName(HOST);

  Socket socket = null;

  try{
      socket = new Socket(addr, PORT);
  }catch(IOException e){
      e.printStackTrace();
      System.exit(-1);
  }

  doSomethingWithThisConnection(socket);
      
  try{
      socket.close();
  }catch(IOException e){
      e.printStackTrace();
      System.exit(-1);
  }


The application simulates each connection by spawning a thread to run the above code to connect to remote server. Gradually increase the number of threads and once the number reaches certain number around 100, you would get somethings similar to the followings:


java.net.ConnectException: Connection refused: connect
	at java.net.PlainSocketImpl.socketConnect(Native Method)
	at java.net.PlainSocketImpl.doConnect(Unknown Source)
	at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
	at java.net.PlainSocketImpl.connect(Unknown Source)
	at java.net.SocksSocketImpl.connect(Unknown Source)
	at java.net.Socket.connect(Unknown Source)
	at java.net.Socket.connect(Unknown Source)
	at java.net.Socket.<init>(Unknown Source)
	at java.net.Socket.<init>(Unknown Source)






References:

 


 
Powered by ForumEasy © 2002-2022, All Rights Reserved. | Privacy Policy | Terms of Use
 
Get your own forum today. It's easy and free.