Question: Our application is "sometimes" timing out, we have a Java client connecting to a unix daemon and for some reason it is now and again throwing the following error:

```
SocketException: Cannot establish connection to daemon
java.net.ConnectException: Connection timed out: connect
    at sun.nio.ch.Net.connect(Native Method)
    at sun.nio.ch.SocketChannelImpl.connect(Unknown Source)
    at java.nio.channels.SocketChannel.open(Unknown Source)
    at ....
    at java.lang.Thread.run(Unknown Source)

```

This stack trace is from the following code:

```
  try
  {
    InetSocketAddress inetAddress = new InetSocketAddress(InetAddress.getByName(serverName), serverPort);
    socketChannel = SocketChannel.open(inetAddress); // <--- I think the problem is here
    pipeSck = socketChannel.socket();

  }
  catch (NoRouteToHostException e)//when the remote host cannot be reached or connection was refused
  {
    System.err.println("NoRouteToHostException: Cannot establish connection to daemon");
    e.printStackTrace();
    return 1; /* reply only with error */
  }
  catch (SocketException e)//when the remote host cannot be reached or connection was refused
  {
    System.err.println("SocketException: Cannot establish connection to daemon");
    e.printStackTrace();
    return 1; /* reply only with error */
  }

```

This works 99% of the time... any ideas why we are getting the timeout?

Thanks!

Answer: 
'Connection timed out' means either that the network was temporarily down, which is the most likely, or, if it isn't running on Windows, that the server's socket backlog queue was full, which could happen under extreme load or denial-of-service attacks.
I'd agree with Crollster, although you could also check to see if you have a firewall on the host that may be causing problems. Does the UNIX hose have a firewall? Any intermediate firewalls? Is the UNIX host on the local LAN? If not, do you have spotty internet access? Networking is fun. :)