Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTP persistent connection vs TCP socket connection

From this article on Wikipedia:

Keepalive messages were not officially supported in HTTP 1.0. In HTTP 1.1 all connections are considered persistent, unless declared otherwise.

  • Does this mean that using this mechanism I can actually simulate a TCP socket connection?
  • Using this can I make a Server "push" data to a client?
  • Are all HTTP connections, even the one I am using to connect to Stack Overflow "HTTP persistent"?
  • Does the COMET technology of server push use this mechanism of HTTP persistent connection to push data to clients?
like image 897
Kevin Boyd Avatar asked Sep 26 '09 02:09

Kevin Boyd


People also ask

What are the advantages of allowing persistent TCP connections in HTTP?

Advantages. Reduced latency in subsequent requests (no handshaking and no slow start). Reduced CPU usage and round-trips because of fewer new connections and TLS handshakes. Enables HTTP pipelining of requests and responses.

What is the difference between HTTP and socket?

Unlike HTTP, where you have to constantly request updates, with websockets, updates are sent immediately when they are available. WebSockets keeps a single, persistent connection open while eliminating latency problems that arise with HTTP request/response-based methods.

Does HTTP use TCP sockets?

HTTP applications use TCP connections for their transport layer, and Figure 4.5. 1 shows the basic structure of HTTP in relation to the functions that establish the socket connection. The client—a web browser—sends an HTTP request to the server and receives a response.

Does HTTP use multiple TCP connections?

In one of the pairs of protocols given below, both the protocols can use multiple TCP connections between the same client and the server. Which one is that? Explanation: HTTP may use different TCP connection for different objects of a webpage if non-persistent connections are used.


2 Answers

  • Does this mean that using this mechanism I can actually simulate a TCP socket connection?

Not really, sockets have MANY more features and flexibility.

  • Using this can I make a Server "push" data to a client?

Not directly, it's still a request/response protocol; the persistent connection just means the client can use the same underlying socket to send multiple requests and receive the respective responses.

  • Are all HTTP connections, even the one I am using to connect to Stack Overflow "HTTP persistent"?

Unless your browser (or a peculiar server) says otherwise, yes.

  • Does the COMET technology of server push use this mechanism of HTTP persistent connection to push data to clients?

Kinda (for streaming, at least), but with a lot of whipped cream on top. There are other Comet implementation approaches, such as hidden iframes and AJAX long polling, that may not require persistent connections (which give some firewalls &c the fits anyway;-).

like image 62
Alex Martelli Avatar answered Sep 19 '22 11:09

Alex Martelli


Actually, the HTTP server can "push" data to a connected http client without the client requesting it. See "HTTP server push" at http://en.wikipedia.org/wiki/Push_technology. However it does seem to be commonly implemented.

like image 41
Michael Avatar answered Sep 20 '22 11:09

Michael