TCP层连接的复用,依靠的tcp client端的端口号保持不变,重复使用
By fault, for HTTP/1.0 GET request, the server closes the TCP connection once the response is delivered. You could request for the TCP connection to be maintained, (so as to send another request using the same TCP connection, to improve on the network efficiency), via an optional request header "Connection: Keep-Alive". The server includes a "Connection: Keep-Alive" response header to inform the client that he can send another request using this connection, before the keep-alive timeout. Another response header "Keep-Alive: timeout=x, max=x" tells the client the timeout (in seconds) and the maximum number of requests that can be sent via this persistent connection.
GET /test.html HTTP/1.0 Connection: Keep-Alive (blank line) HTTP/1.1 200 OK Date: Sun, 18 Oct 2009 10:47:06 GMT Server: Apache/2.2.14 (Win32) Last-Modified: Sat, 20 Nov 2004 07:16:26 GMT ETag: "10000000565a5-2c-3e94b66c2e680" Accept-Ranges: bytes Content-Length: 44 Keep-Alive: timeout=5, max=100 Connection: Keep-Alive Content-Type: text/html <html><body><h1>It works!</h1></body></html>Notes:
The message "Connection to host lost" (for telnet) appears after "keep-alive" timeoutBefore the "Connection to host lost" message appears (i.e., Keep-alive timeout), you can send another request through the same TCP connection.The header "Connection: Keep-alive" is not case sensitive. The space is optional.If an optional header is misspelled or invalid, it will be ignored by the server.