HTTP persistent connection vs TCP socket connection

Kevin Boyd picture Kevin Boyd · Sep 26, 2009 · Viewed 13.6k times · Source

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?

Answer

Alex Martelli picture Alex Martelli · Sep 26, 2009
  • 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;-).