Issue Details (XML | Word | Printable)

Key: NET-141
Type: Improvement Improvement
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Daniel Savarese
Reporter: Christian Hufgard
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Commons Net

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

Created: 25/Sep/06 10:09 AM   Updated: 20/Sep/07 05:31 AM
Return to search
Component/s: None
Affects Version/s: 1.4
Fix Version/s: 2.0

Time Tracking:
Not Specified

File Attachments:
  Size
Java Source File Licensed for inclusion in ASF works CustomSocketFactory.java 2006-09-25 10:17 AM Christian Hufgard 2 kB

Resolution Date: 06/Dec/06 01:03 AM


 Description  « Hide
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



 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Christian Hufgard made changes - 25/Sep/06 10:17 AM
Field Original Value New Value
Attachment CustomSocketFactory.java [ 12341613 ]
Daniel Savarese made changes - 26/Sep/06 03:26 PM
Summary FTPClient/DefaultSocketFactory does not regard default timeout Add connection timeout support to SocketClient and/or SocketFactory/DefaultSocketFactory
Issue Type Bug [ 1 ] Improvement [ 4 ]
Assignee Daniel Savarese [ dfs@apache.org ]
Fix Version/s 2.0 [ 12312040 ]
Rory Winston made changes - 06/Dec/06 01:03 AM
Resolution Fixed [ 1 ]
Status Open [ 1 ] Resolved [ 5 ]
Henri Yandell made changes - 20/Sep/07 05:31 AM
Status Resolved [ 5 ] Closed [ 6 ]