Monday, 2 April 2012

Push technology


Push, or server push, describes a style of Internet-based communication where the request for a given transaction is initiated by the publisher or central server. It is contrasted with pull, where the request for the transmission of information is initiated by the receiver or client.


HTTP server push
HTTP server push (also known as HTTP streaming) is a mechanism for sending data from a web server to a web browser. HTTP server push can be achieved through several mechanisms.
Generally the web server does not terminate a connection after response data has been served to a client. The web server leaves the connection open such that if an event is received, it can immediately be sent to one or multiple clients. Otherwise the data would have to be queued until the client's next request is received. Most web servers offer this functionality via CGI (e.g. Non-Parsed Headers scripts on Apache).
Another mechanism is related to a special MIME type called multipart/x-mixed-replace, which was introduced by Netscape in 1995. Web browsers would interpret this as a document changing whenever the server felt like pushing a new version to the client. It is still supported by Firefox, Opera and Safari today, but ignored by Internet Explorer. It can be applied to HTML documents, and also for streaming images in webcam applications.
The WHATWG Web Applications 1.0 proposal included a mechanism to push content to the client. On September 1, 2006, the Opera web browser implemented this new experimental coding in a feature called "Server-Sent Events". It is now being standardized as part of HTML5. Another related part of HTML5 is the WebSockets API, which allows a web server and client to communicate over a full-duplex TCP connection.


Pushlet
In this technique, the server takes advantage of persistent HTTP connections and leaves the response perpetually "open" (i.e. it never terminates the response), effectively fooling the browser into continuing in "loading" mode after the initial page load would normally be complete. The server then periodically sends snippets of JavaScript to update the content of the page, thereby achieving push capability. By using this technique the client doesn't need Java applets or other plug-ins to keep an open connection to the server. The clients will be automatically notified by new events, pushed by the server. One serious drawback to this method, however, is the lack of control the server has over the browser timing out. A page refresh is always necessary if a timeout occurs on the browser end.


Long polling
Long polling is a variation of the traditional polling technique and allows emulation of an information push from a server to a client. With long polling, the client requests information from the server in a similar way to a normal poll. However, if the server does not have any information available for the client, instead of sending an empty response, the server holds the request and waits for some information to be available. Once the information becomes available (or after a suitable timeout), a complete response is sent to the client. The client will normally then immediately re-request information from the server, so that the server will almost always have an available waiting request that it can use to deliver data in response to an event. In a web/AJAX context, long polling is also known as Comet programming.
Long polling is itself not a push code, but can be used under circumstances where a real push is not possible

No comments: