网络timeout区分

时间:2024-06-28 08:04:13

ConnectTimeout

连接建立时间,三次握手完成时间

SocketTimeout

数据传输过程中数据包之间间隔的最大时间

下面重点说下SocketTimeout,比如有如下图所示的http请求

网络timeout区分

虽然报文(“abc”)返回总共用了6秒,如果SocketTimeout设置成4秒,实际程序执行的时候是不会抛出java.net.SocketTimeoutException: Read timed out异常的。

因为SocketTimeout的值表示的是“a”、”b”、”c”这三个报文,每两个相邻的报文的间隔时间不能超过SocketTimeout

ReadTimeout

2. ReadTimeout , java 是这样解释的。 意思是已经建立连接,并开始读取服务端资源。如果到了指定的时间,没有可能的数据被客户端读取,则报异常。

  1. Sets the read timeout to a specified timeout, in milliseconds. A non-zero value specifies the timeout when reading from Input stream when a connection is established to a resource. If the timeout expires before there is data available for read, a java.net.SocketTimeoutException is raised. A timeout of zero is interpreted as an infinite timeout.
  2. Some non-standard implementation of this method ignores the specified timeout. To see the read timeout set, please call getReadTimeout().