3 个问题:
套接字的连接和读取超时有什么区别?
连接超时设置为“无限”是什么意思?在什么情况下它可以保持在不定式循环中?什么会触发无限循环死亡?
read 超时设置为“无限”是什么意思?在什么情况下它可以保持在不定式循环中?什么会触发无限循环死亡?
最佳答案
- What is the difference between connection and read timeout for sockets?
连接超时是建立初始连接的超时时间;即完成 TCP 连接握手。读取超时是等待读取数据的超时时间1。如果在客户端调用套接字 read
后服务器(或网络)未能传递任何数据
- What does connection timeout set to "infinity" mean? In what situation can it remain in an infinitive loop? and what can trigger that the infinity-loop dies?
这意味着连接尝试可能永远阻塞。没有无限循环,但连接尝试可以被另一个关闭套接字的线程解除阻塞。 (Thread.interrupt()
调用也可以解决问题……不确定。)
- What does read timeout set to "infinity" mean? In what situation can it remain in an infinite loop? What can trigger that the infinite loop to end?
这意味着对套接字流上的 read
的调用可能会永远阻塞。再次没有无限循环,但 read
可以通过 Thread.interrupt()
调用解除阻塞,关闭套接字,(当然)另一端发送数据或关闭连接。
1 - 这不是......正如一位评论者所认为的......套接字可以打开或空闲多长时间的超时。
关于java - 套接字的连接和读取超时有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3069382/