套接字的连接超时和读取超时有什么区别? [英] What is the difference between connection and read timeout for sockets?

查看:84
本文介绍了套接字的连接超时和读取超时有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

3 个问题:

  1. 套接字的连接读取超时有什么区别?

  2. connection 超时设置为无穷大"是什么意思?在什么情况下它可以保持在不定式循环中?什么可以触发无限循环终止?

  3. read 超时设置为无穷大"是什么意思?在什么情况下它可以保持在不定式循环中?什么可以触发无限循环终止?

解决方案

  1. 套接字的连接超时和读取超时有什么区别?

连接超时是进行初始连接的超时时间;即完成 TCP 连接握手.读取超时是等待读取数据的超时时间1.如果服务器(或网络)未能传送任何数据,则客户端发出套接字 read 调用后的几秒钟内,将引发读取超时错误.

<块引用>

  1. 连接超时设置为无穷大"是什么意思?意思是?在什么情况下它可以保持在不定式循环中?什么可以触发无限循环终止?

这意味着连接尝试可能会永远阻塞.没有无限循环,但是连接的尝试可以被关闭套接字的另一个线程解除阻塞.(Thread.interrupt() 调用也可以做到这一点......不确定.)

<块引用>

  1. 什么是读取超时设置为无穷大"?意思是?什么情况下可以无限循环?什么可以触发无限循环结束?

这意味着对套接字流的read 调用可能会永远阻塞.再次没有无限循环,但是 read 可以通过 Thread.interrupt() 调用解除阻塞,关闭套接字,(当然)另一端发送数据或关闭连接.


1 - 这不是......正如一位评论者所想的......套接字可以打开或空闲多长时间的超时.

3 questions:

  1. What is the difference between connection and read timeout for sockets?

  2. 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?

  3. 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?

解决方案

  1. 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.

  1. 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.)

  1. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆