Socket.connect(Areess,timeout) 和 FTPClient.setSoTimeOu 之间的区别

发布于 2024-08-04 07:09:16 字数 361 浏览 2 评论 0原文

我们正在通过我们的应用程序(JAVA 应用程序)进行 FTP 连接。 在调用 FTPClient.connect() 方法之前,我们已经使用 Socket.connect(Areess,timeout) 方法设置了连接超时。

在同一连接下从 FTP 站点检索文件期间,我们没有设置任何超时。是否必须调用 FTPClient.setSoTimeOut(timeout) 方法来为同一连接下的每个此类交互设置单独的超时,或者 Socket.connect(Areess,timeout) 方法将为一个连接下与 FTP 站点的每次交互设置超时?

我也想知道这两种方法有什么区别?

We are doing FTP connection through our applicaion which is a JAVA aplication.
We have set timeout for connection using Socket.connect(Adreess,timeout) method before calling FTPClient.connect() method.

During retriving files from the FTP site under same connection we havent set any timeout. Is it mandatory to call method FTPClient.setSoTimeOut(timeout) method to set individual time out for each such interaction under same connection or Socket.connect(Adreess,timeout) method will set timeout for each interaction with FTP site under one connection?

I would also like to know What is the difference between these two methods?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

離人涙 2024-08-11 07:09:16

Socket.connect()中的超时是connect timeout,即等待TCP握手完成的时间。每个连接仅发生一次此超时。

setSoTimeout() 称为套接字读取超时,即等待从套接字读取待处理字节的时间。这发生在整个 TCP 会话中读取的每个套接字上。

最好设置两个超时值,这样您就不必依赖系统默认值,因为系统默认值可能会有所不同。但是,当调用卡在本机代码中时,超时有时可能不起作用。例如,如果防火墙默默地丢弃数据包,则不会遵守连接超时。

The timeout in Socket.connect() is connect timeout, which is the time to wait for TCP handshake to finish. This timeout only occurs once per connection.

setSoTimeout() is called socket read timeout, which is how long you wait to read pending bytes from socket. This occurs on every socket read throughout the TCP session.

It's good practice to set both timeout value so you don't rely on system defaults, which may vary. However, the timeout may not work sometimes when the call is stuck in native code. For example, the connect timeout is not honored if firewall silently drops packet.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文