Uploaded image for project: 'Commons Net'
  1. Commons Net
  2. NET-141

Add connection timeout support to SocketClient and/or SocketFactory/DefaultSocketFactory

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.4
    • 2.0
    • None
    • None

    Description

      Hi,

      If executing the following code
      String hostname = "localhost";
      FTPClient client = new FTPClient();
      client.setDefaultTimeout(1000);
      client.connect(hostname);

      against a ftp server that ignores the connection attempt (e.g. is firewalled/malfunctoned), there will be no exception after 1000 ms. The exception will be thrown after a default timeout of three minutes. (Three minutes on a debian/ and a suse machines. Might be different on other platforms).

      JavaDoc says:
      public void setDefaultTimeout(int timeout)
      Set the default timeout in milliseconds to use when opening a socket.

      Digging through the code I found, that DefaultSocketFactory which is used be SocketClient does not care about any value set with this method. It creates a new Socket with Socket(hostname, port) and relies on the VMs behaviour.

      To get this fixed I set a custom SocketFactory with client.setSocketFactory(socketFactory); that uses a timeout for socket connection.

      This bug is also in 1.4.1, but this value is not listed...

      Christian

      Attachments

        1. CustomSocketFactory.java
          2 kB
          Christian Hufgard

        Activity

          People

            dfs@apache.org Daniel Savarese
            christian.hufgard@gmx.de Christian Hufgard
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: