httpclient Timeout Time
Description
Connectionrequesttimeout
HttpClient uses connection pooling to manage connections, which is the timeout to get connections from the connection pool, and you can imagine the database connection pool connecttimeout
Connection establishment time, three handshake completion time sockettimeout
Maximum time interval between packets during data transfer
The following highlights the sockettimeout, such as the HTTP request as shown in the following figure
Although the message ("ABC") returns a total of 6 seconds, if the sockettimeout is set to 4 seconds, the actual program will not throw Java.net.SocketTimeoutException:Read timed out exception.
Because the value of the sockettimeout represents the three messages "a", "B", "C", each of the two adjacent packets must not exceed sockettimeout. Program Validation: Server End (PYTHON3): Returns a, B, C every 3 seconds
__author__ = ' Yanglikun ' from
flask import flask to
flask import Response Import time
app = Flask (__nam e__)
@app. Route ("/")
def hello ():
def generate ():
for row in ["A", "B", "C"]:
time.sleep (3)
Yield row;
Return Response (Generate ());
if __name__ = = "__main__":
app.run (host= ' 0.0.0.0 ', port=8897)
Java Client (httpclient 4.3.6)
Closeablehttpclient client = Httpclientbuilder.create (). build ();
Requestconfig config = Requestconfig.custom (). Setconnectionrequesttimeout (5)
. Setconnecttimeout (5)
. SetSocketTimeout (6000). Build ();
HttpGet httpget = new HttpGet ("http://192.168.147.90:8897/");
Httpget.setconfig (config);
Long begin = System.currenttimemillis ();
String respstr = null;
try {
Closeablehttpresponse resp = Client.execute (httpget);
Respstr = entityutils.tostring (Resp.getentity ());
} catch (IOException e) {
e.printstacktrace ();
}
System.err.println ("Respstr:" + respstr);
System.err.println ("End:" + (System.currenttimemillis ()-begin);
Client Execution Results
Although the setting Sockettimeout is 6000 (6 seconds), the program executes for 9 seconds and does not throw Java.net.SocketTimeoutException:Read timed out exception
Wireshark Grab Bag result
Might think that the actual message is not every 3 seconds after the return of a message, the following is through the Wireshark grab bag results
which
1: Returns the TCP message of letter A
2: Returns the TCP message of the letter B
3: Returns the TCP message of letter C
According to the time column, you can see that the interval between TCP data transmission is 3 seconds written in the Python program. BTW, you can review another TCP knowledge, each message has an ACK message, is the TCP client receipt message
Click to view larger image