go to  ForumEasy.com   
JavaPro
Home » Archive » Message


[Email To Friend][View in Live Context][prev topic « prev post | next post » next topic]
  java.net.ConnectException: Connection refused: connect
 
Subject: java.net.ConnectException: Connection refused: connect
Author: EricJ
Posted on: 04/13/2007 02:09:21 PM

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)



Replies:


References:

 


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