I implement class UtSocketFactory extends from class
DefaultSocketFactory, and FTPClient.setSocketFactory
for it. It has resolved the problem that I sumbit.
Thanks for Daniel's help!!!
The following is my code for new SocketFactory:
--------
UtSocketFactory utSocketFactory = new
UtSocketFactory();
utSocketFactory.setConnectTimeout(5000);
FTPClient ftp = new FTPClient();
ftp.setSocketFactory(utSocketFactory);
try {
ftp.connect(server, port);
} catch (Exception e) {
e.printStackTrace();
if (ftp.isConnected()) {
try {
ftp.disconnect();
} catch (Exception f) {
// do nothing
}
}
return RTN_CODE_FTP_SERVER_CONNECTION_ERROR;
}
The following is the class UtSocketFactory:
----------
public class UtSocketFactory extends
DefaultSocketFactory {
private int connectTimeout = 0;
/**
*
*/
public UtSocketFactory() {
super();
}
/* (non-Javadoc)
* @see
org.apache.commons.net.SocketFactory#createSocket(java.lang.String,
int)
*/
public Socket createSocket(String host, int port)
throws UnknownHostException, IOException {
Socket s = new java.net.Socket();
java.net.InetSocketAddress addr =
new java.net.InetSocketAddress(host, port);
s.connect(addr, connectTimeout);
return s;
}
/**
* @return
*/
public int getConnectTimeout() {
return connectTimeout;
}
/**
* @param i
*/
public void setConnectTimeout(int i) {
connectTimeout = i;
}
}
--- "Daniel F. Savarese" <[EMAIL PROTECTED]> wrote:
>
> In message
>
<[EMAIL PROTECTED]>,
> aha writes:
> >When I modified the code as following, it looks
> that
> >resolved it.
>
> Ideally, you would implement your own SocketFactory,
> perhaps by subclassing
> DefaultSocketFactory, and use setSocketFactory.
> Otherwise, you have to
> modify the code every time there's a new Commons Net
> release. Since
> Commons Net 1.2 is using J2SE 1.2 as a compatibility
> baseline, the Socket
> API additions that should have been in java.net from
> the start haven't
> been incorporated.
>
> >To all: Is it correct??? Any comments are welcome!
>
> Yes, because the new Socket.connect method allows
> you to override
> the connection timeout. Previous to J2SE 1.4, you
> were stuck with
> the OS TCP stack default value and forced to use
> native code or play
> tricks with threads and timers to abort a connection
> attempt that
> was taking too long.
>
> daniel
__________________________________
Do you Yahoo!?
Yahoo! Mail - You care about security. So do we.
http://promotions.yahoo.com/new_mail
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]