Why achieving real time connection was difficult with HTTP protocol. As HTTP is implemented over TCP connection which is reliable and continuing the persistent connection should be easier . right?. How Web Sockets solves this persistent connection problem?
-
I'm not sure what you are asking. In the title and first sentence you ask about "real time connection" which has no clear meaning, even "real time" is a very context depending phrase. Then you ask about persistence and Websockets which has nothing to do with "real time" in the title. It might be more clear if you present an example and/or quotes or links to other site to give more context to your question. Maybe just show the actual problem you want to solve and which can be done with Websockets but not with plain HTTP? – Steffen Ullrich Jan 31 '20 at 14:01
1 Answers
Prior to HTTP/2, HTTP/0.9 and HTTP/1.x were just command+response protocols only. A client would send a command, the server would send a reply, done, nothing more. And prior to HTTP/1.1, keeping the TCP connection alive after each response was impossible in HTTP/0.9 and not common practice in HTTP/1.0. HTTP/1.1 standardized that practice.
So it was very difficult to implement any kind of persistent real-time bi-direction communications over HTTP until recent years. Sure, various technologies were devised to try to address this (long polling, server-side pushes, etc), but nothing was really widely accepted and put into common practice across all implementations.
Then WebSockets came along, which was specifically designed for persistent bi-directional communications, in such a way that was easy to add to existing HTTP infrastructures so server admins didn't have to re-invest in new technologies, while maintaining backwards compatibility with older HTTP systems that can't/won't support WebSockets.
Then HTTP/2 came along, which now has server pushes and multiplexing built right in to the HTTP protocol, solving many of the shortcomings of old HTTP versions, and covers some of the use-cases that WebSockets were being used for, but doesn't obsolete Websockets completely.
HTTP has a very long history of evolution to get to where it is today. Evolution takes time.

- 555,201
- 31
- 458
- 770