本文介绍了setConnectionTimeout,setSoTimeout和“http.connection-manager.timeout”之间的区别是什么?在apache HttpClient API中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

三者之间有什么区别(标记为评论):

What is the difference between the three(marked as comments) :

MultiThreadedHttpConnectionManager connManag =  new MultiThreadedHttpConnectionManager();
HttpConnectionManagerParams managParams = connManag.getParams();

managParams.setConnectionTimeout(connectiontimeout); // 1
managParams.setSoTimeout(sotimeout); //2

HttpMethodBase baseMethod = null;

try {
  HttpClient client = new HttpClient(connManag);
  client.getParams().setParameter("http.connection-manager.timeout", poolTimeout); //3

  baseMethod = new GetMethod(…);
  int statusCode = client.executeMethod(…);

  …
}
catch (ConnectTimeoutException cte ){
  //Took too long to connect to remote host
}
catch (SocketTimeoutException ste){
  //Remote host didn’t respond in time
}
catch (Exception se){
  //Some other error occurred
}
finally {
  if (baseMethod != null)
    baseMethod.releaseConnection();
}

1。 setConnectionTimeout - 如果确定连接建立之前的超时时间。

1. setConnectionTimeout - if it determines the timeout until connection is established.

2。 setSoTimeout - 如果确定两个连续数据包之间的不活动时间或时间差,

2. setSoTimeout - if it determines the period of inactivity or time difference between two consecutive packets ,

那么下面的内容是做什么的:

Then what does the below one do :

3。 http.connection-manager.timeout

推荐答案

在最低级别,HTTP是TCP套接字。因此,当您请求URL并获得响应时,在较低级别创建一个客户端Socket,它建立与远程服务器套接字的连接,发送一些数据并接收响应。

At the lowest level HTTP is TCP socket. So when you request a URL and get a response, at lower level, a client Socket is created which establishes connection to the remote Server Socket, sends some data and receives response.


  • setConnectionTimeout :客户端尝试连接到服务器。这表示建立连接或服务器响应连接请求之前经过的时间。

  • setConnectionTimeout : Client tries to connect to the server. This denotes the time elapsed before the connection established or Server responded to connection request.

setSoTimeout :建立连接后,客户端套接字在发送请求后等待响应。这是自客户端在服务器响应之前向服务器发送请求以来经过的时间。请注意,这与服务器发送给客户端的 HTTP错误408 不同。换句话说,在建立连接之后到达客户端的两个连续数据包之间的最大周期不活动

setSoTimeout : After establishing the connection, the client socket waits for response after sending the request. This is the elapsed time since the client has sent request to the server before server responds. Please note that this is not same as HTTP Error 408 which the server sends to the client. In other words its maximum period inactivity between two consecutive data packets arriving at client side after connection is established.

http.connection-manager.timeout MultiThreadedHttpConnectionManager 使用 HTTP连接池。它为每个主机设置了最大值和最小值。如果特定主机的所有连接都已达到最大值,则同一主机的新连接请求必须等到任何一个现有连接都空闲。此参数表示在发出连接请求时以及 HttpConnectionManager 返回连接之前经过的时间。

http.connection-manager.timeout : MultiThreadedHttpConnectionManager uses a pool of HTTP connections. It has maximum and minimum values per host set for it. If all the connections for particular host are has reached max value, the request for new connection for the same host will have to wait till any one of the existing connection becomes free. This parameter denotes the time elapsed when a connection request was made and before the HttpConnectionManager returned a connection.

这篇关于setConnectionTimeout,setSoTimeout和“http.connection-manager.timeout”之间的区别是什么?在apache HttpClient API中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 06:31