Persistent Connection

A persistent connection gives the ability to use the same TCP connection for multiple HTTP transactions instead of opening a new connection for each HTTP request you send. It reduces traffic on the network since the TCP 3-Way-Handshake and the TCP Graceful Connection Close are only done once instead of at each HTTP transaction. However, HTTP transactions on a persistent connection are performed one after the other and therefore cannot be parallelized.

In HTTP v1.0, there was no inherent way to open a persistent connection with the server. Thus, a new HTTP header was added later on: "Connection: Keep-Alive". This header was added to each HTTP request to inform the server that the connection was intended to be persistent. The server would send the response with the same header to inform the client that it supported persistent mode. At that point, the connection was left open until one of the client or server decided to close the connection.

In the latest HTTP v1.1, connections are by default considered persistent. A header "Connection: close" is added to the request or response to explicitly inform the other party to close the connection after the end of the HTTP transaction. Many web browsers still add the "Connection: Keep-Alive" header in their requests for backward compatibility.

µC/HTTP-server

The Persistent Connection support can be enabled in the µC/HTTP-server. In that case, the server will close the connection at the end of a transaction only if the header "Connection: close" was received in the HTTP request, else the connection will be maintain open until the HTTP client decides to close the connection or until the server connection inactivity timeout is reached. When the feature is disabled, the HTTP server will always add the "Connection: close" header to the HTTP response and will always closed the connection after the transaction is completed.

See Section Persistent Connection Configuration to enable the Persistent Connection Option feature.

See Section Instance Parameters Configuration to enable the Persistent Connection feature in the HTTP Server Instance run-time configuration.

µC/HTTP-client

µC/HTTP-client supports persistent connection. However, since µC/HTTP-client only supports HTTP v1.1, the header "Connection : Keep-Alive" is not supported. When the persistent connection mode is disabled, the header "Connection: close" will be automatically  added to the request; and when the persistent connection mode is enabled, no header will be added. Furthermore, if a "Connection: close" header is received when none was sent, the client will close the connection if the server hasn't already.

See Section Persistent Connection Configuration to enable the Persistent Connection Option feature.

See Section Persistent Connection for a example with the Persistent Connection mode enabled.