为什么 FTPClient.setDefaultTimeout 不起作用?
我正在尝试使用 FTPClient 在 Java 中建立 ftp 连接。
我想看看当我分开服务器和客户端之间的界限时会发生什么。我的应用程序冻结了大约 30 秒,然后抛出一个 ConnectionException
(连接超时)。这就是为什么我为 FTPCliend 搜索超时方法,并找到了 setDefaultTimeout()
所以我将该方法放在连接尝试之前,但它仍然冻结了 30 秒...
FTPClient ftp = new FTPClient();
ftp.setDefaultTimeout(5000);
ftp.connect(ip);
当我输入“1.1.1.1”时作为ip
,应用程序快速抛出ConnectionException
(连接被拒绝),但是当我输入正确的ip地址时,它只是冻结(30秒)并且抛出ConnectionException
而不是期望的TimeoutException(5秒后)
我做错了什么?
PS:请原谅我糟糕的英语知识;)
I am trying to make a ftp connection in Java with FTPClient.
I wanted to look what happens when i separate the line between Server and Client. My application freezed about 30seconds and then it thows a ConnectionException
(Connection timed out). Thats why I searched for a timeout method for the FTPCliend and I found setDefaultTimeout()
so I put the method before the connection attemp but it still freezed 30 sec...
FTPClient ftp = new FTPClient();
ftp.setDefaultTimeout(5000);
ftp.connect(ip);
When i put "1.1.1.1" as ip
the application throws fastly a ConnectionException
(Connection refused) but when i put the right ipAdress its just freezing(30sec) and threwing the ConnectionException
instead of the wished TimeoutException (after 5sec)
What am I doing wrong?
ps: excuse my horrible english knowledge ;)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定您使用的是哪个
FTPClient
,因为有几个。然而,它们通常有两种不同的超时选项:一种用于数据,一种用于实际连接。我建议您搜索名为setConnectTimeout()
或类似的方法。I'm not sure which
FTPClient
you're using because there are a couple out there. However, they usually have two different timeout options : one for data and one for actual connection. I suggest you search for a method calledsetConnectTimeout()
or similar.