commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Wayne Johnson (JIRA)" <j...@apache.org>
Subject [jira] Commented: (NET-141) Add connection timeout support to SocketClient and/or SocketFactory/DefaultSocketFactory
Date Mon, 03 May 2010 16:46:58 GMT

    [ https://issues.apache.org/jira/browse/NET-141?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12863400#action_12863400
] 

Wayne Johnson commented on NET-141:
-----------------------------------

I ran into a similar issue when using RCommandClient.  I implemented Christian's solution
and had two problems.  Noting them here for anyone attempting the same.

1) RCommandClient will automatically retry a connect on another port pair on a ConnectException
in the socket.connect.  This is really a bug in RcommandClient.  To get around this I added
a catch to Christian's code to catch a ConnectException and rethrow it as a IOException. 


2) There is a typo in Christian's code in the method when using InetAddress to createSocket().
 The code should be

	    public Socket createSocket(InetAddress address, int port, InetAddress localAddress, int
localPort) 
	        throws IOException 
	    {
	        return createSocket(address.getHostName(), port, localAddress, localPort);
	    }

Note that the original code passed 0 for the localPort when the user had specified a localPort.


> Add connection timeout support to SocketClient and/or SocketFactory/DefaultSocketFactory
> ----------------------------------------------------------------------------------------
>
>                 Key: NET-141
>                 URL: https://issues.apache.org/jira/browse/NET-141
>             Project: Commons Net
>          Issue Type: Improvement
>    Affects Versions: 1.4
>            Reporter: Christian Hufgard
>            Assignee: Daniel Savarese
>             Fix For: 2.0
>
>         Attachments: CustomSocketFactory.java
>
>
> 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

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message