Note: Reverse Ajax – communication is started by the server and not the client Limitation/HTTP – always client who initiates a communication by browsing a site “Reverse” – every subsequent data interchange will be initialized by the server Introduction Asynchronously send data from the server to the client (browser). Repeated AJAX requests from the clients Server can send events to the client as quickly as possible (low-latency communication) Applications Chat application Stock updates Temperature update Cricket scores Auctions Opinion polls HTTP Polling (by the client) Similar to regular AJAX HTTP requests To get server events asap, Browser makes a request to the server at regular and frequent intervals say every 3 secs (polling interval), to check an update Drawbacks: Frequent requests – no data, consume bandwidth Comet (Long Poll) a web application model request is sent, kept alive for a long time, until a time-out or a server event occurs When completed, another long-lived Ajax request is sent to wait for other events Server can push events on the clients immediately as they arrive even accumulate and send bursts Comet (Streaming) In streaming - one persistent connection is opened Requirement on client side - a way to separate the different responses coming through the same connection Forever Iframes (hidden IFrames) XMLHTTPRequest Using Hidden Iframes Hidden Iframe tag – src attribute - pointing to the servlet path returning server events Each time an event is received, the servlet writes and flushes a new script tag Poll a script on the server (using ajax) on a given interval Using XMLHTTPRequest Open an Ajax request to the server and wait for the response Server side to allow the request to be suspended As soon as an event occurs, the server sends back the response in the suspended request and closes it HTML5 Server Sent Events Web page automatically gets updates from a server. Web page hold an open connection to the web server Updates can be streamed from server to client as they happen Facebook/Twitter updates, stock price updates, news feeds, scores, etc. Web Sockets Based on HTML5 enables bidirectional, full-duplex communication channels Connection is opened – HTTP Request – WebSockets handshake Has special headers in request Connection is kept alive, and you can write and receive data in JavaScript