title: java.net.SocketException Connection timed out error
body: <p>I am getting below error when I am trying to connect to a TCP server. My programs tries to open around 300-400 connections using diffferent threads and this is happening during 250th thread. Each thread uses its own connection to send and receive data.</p>
  
  <pre><code>java.net.SocketException: Connection timed out:could be due to invalid address
      at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:372)
      at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:233)
      at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:220)
      at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:385)
  </code></pre>
  
  <p>Here is the code I have that a thread uses to get socket:</p>
  
  <pre><code>socket = new Socket(my_hostName, my_port);
  </code></pre>
  
  <p>Is there any default limit on number of connections that a TCP server can have at one time? If not how to solve this type of problems?</p>