Comet introduction:
While still admiring Ajax, comet has quietly arrived, and has even compared comet to the successor of Ajax. At present, comet is becoming increasingly popular without considering the service performance and the burden of maintaining connection. In the traditional C/S mode, server push requires the implementation of thread service and socket communication, it is derived from a Web application framework that uses event and script registration mechanisms.
Server push, just like its own name, pushes more gorgeous web experiences into our field of view.
An engineer named Grace Lin gave a detailed introduction to the online stock system using server push technology in his blog. (Address: http://www.zkoss.org/smalltalks/stockchart/) at the same time, there are a lot of IM applications emerging. This topic compares the structural features of Ajax and comet, and further analyzes the technical features and Corresponding applications of comet.
Ajax technical framework:
We all understand the structure of Ajax, and we will not explore it further here. The Ajax framework is strange, but in fact it emphasizes the feature of Asynchronization: Asynchronous Server processing and user interface operations after data requests.
Figure 1.1 comparison between traditional and Ajax Models
Ajax is added to the communication framework for asynchronous operation.
Figure 1.2 Ajax Asynchronous Communication Model
It seems that everything is so perfect, but in fact Ajax only implements single-user response callback and asynchronous communication with the server, but it does not reflect the synergy between multiple users. Multiple Ajax Asynchronization operations on a page may allow users to modify data that is not displayed, logically, there is a concept of "Dirty read" or "Phantom read" in database transactions, and the next request is sent without seeing the data (of course, the request is sent to another page element, hopefully, some page elements still refresh the unmodified Ajax request information .) These seem to be the weakness of Ajax. Comet is actually a framework for solving these problems.
Comet technical framework:
Figure 2.1 comparison between Ajax and comet frameworks
On the webpage that uses the comet framework, after page initialization, a connection is maintained and server-side event information is monitored. The server uses the event mechanism to push the browser (or the client.
Different clients listen to events on the server at the same time and obtain data from the server. Each client's request becomes a server event that is "broadcast" on the network ".
Of course, comet needs to be based on a specific server environment, which is also very different from Ajax.
client-based server push technology has appeared on the Internet. In fact, they all use IFRAME, applet, and Flash to implement persistent connections.