套接字的连接超时和读取超时有什么区别? [英] What is the difference between connection and read timeout for sockets?
问题描述
3 个问题:
套接字的连接和读取超时有什么区别?
connection 超时设置为无穷大"是什么意思?在什么情况下它可以保持在不定式循环中?什么可以触发无限循环终止?
read 超时设置为无穷大"是什么意思?在什么情况下它可以保持在不定式循环中?什么可以触发无限循环终止?
- 套接字的连接超时和读取超时有什么区别?
连接超时是进行初始连接的超时时间;即完成 TCP 连接握手.读取超时是等待读取数据的超时时间1.如果服务器(或网络)未能传送任何数据,则read
调用后的几秒钟内,将引发读取超时错误.
- 连接超时设置为无穷大"是什么意思?意思是?在什么情况下它可以保持在不定式循环中?什么可以触发无限循环终止?
这意味着连接尝试可能会永远阻塞.没有无限循环,但是连接的尝试可以被关闭套接字的另一个线程解除阻塞.(Thread.interrupt()
调用也可以做到这一点......不确定.)
- 什么是读取超时设置为无穷大"?意思是?什么情况下可以无限循环?什么可以触发无限循环结束?
这意味着对套接字流的read
调用可能会永远阻塞.再次没有无限循环,但是 read
可以通过 Thread.interrupt()
调用解除阻塞,关闭套接字,(当然)另一端发送数据或关闭连接.
1 - 这不是......正如一位评论者所想的......套接字可以打开或空闲多长时间的超时.
3 questions:
What is the difference between connection and read timeout for sockets?
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?
What does read timeout set to "infinity" mean? In what situation can it remain in an infinitive loop? and what can trigger that the infinity-loop dies?
- What is the difference between connection and read timeout for sockets?
The connection timeout is the timeout in making the initial connection; i.e. completing the TCP connection handshake. The read timeout is the timeout on waiting to read data1. If the server (or network) fails to deliver any data <timeout> seconds after the client makes a socket read
call, a read timeout error will be raised.
- 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?
It means that the connection attempt can potentially block for ever. There is no infinite loop, but the attempt to connect can be unblocked by another thread closing the socket. (A Thread.interrupt()
call may also do the trick ... not sure.)
- 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?
It means that a call to read
on the socket stream may block for ever. Once again there is no infinite loop, but the read
can be unblocked by a Thread.interrupt()
call, closing the socket, and (of course) the other end sending data or closing the connection.
1 - It is not ... as one commenter thought ... the timeout on how long a socket can be open, or idle.
这篇关于套接字的连接超时和读取超时有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!