分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow
也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!
Q: How can I set a connection timeout?
A: setDefaultTimeout does not set the connecttimeout. It provides a default socket timeout. Only in J2SE 1.4 was theability to specify a timeout on connect added to the Socket API. SinceCommons Net 1.2.x has a J2SE 1.2 compatibility requirement, the abilityto specify a connect timeout is not included. The way to workaroundthis is to implement your own SocketFactory and set it with SocketClient.setSocketFactory (FTPClient is a subclass of SocketClient). When you implement the SocketFactory,add a setConnectTimeout method or some such. Inside of the createSocketmethods, use the J2SE 1.4 connect method with the timeout. We couldactually provide socket factory that subclasses DefaultSocketFactoryto do this without breaking backward compatibility, but that would haveto be discussed further. The way to do it is to compile it only if J2SE>= 1.4 is being used. SocketClient could check foravailability of the J2SE 1.4 connect method and instantiate the J2SE>= 1.4 factory if available (using Class.forName and newInstance).The setDefaultTimeout method could then be changed to also set theconnect timeout in the new factory if being used. If users want thisfunctionality enough, the best chance of getting it implemented soon isto submit a patch.
不过我看了 ftpClient 2.0的源代码。
ftpClient.connect(hostName, 21);