SlideShare une entreprise Scribd logo
1  sur  27
Reverse Ajax
Techniques, libraries and support in 2014
Ajax (Asynchronous JavaScript and XML)
• Group of interrelated Web development techniques used on the client-side to
create asynchronous Web applications.
• With Ajax, Web applications can send data to, and retrieve data from a server
asynchronously (in the background) without the need for a page reload.
• It is a browser feature accessible to a web page through the JavaScript.
• Though the name includes XML, nearly anything can be transfered with an Ajax
request.
• The most commonly used data is JSON, which is close to JavaScript syntax and
consumes less bandwidth.
• Ajax requests are stateless by default, and can only be opened from the client to
the server.
Reverse Ajax
• Reverse Ajax is essentially a concept for sending data from the server to the
client.
• It can be simulated with a repeated Ajax request from client – simple polling,
piggyback polling.
• Comet – umbrella term for various techniques for Reverse Ajax
• Coined by Alex Russel in 2006.
• It can be simulated with a long-held Ajax request from client .
• Server can send events to the client without the client specifically requesting it.
• Also known as Ajax Push, Two-way-web, HTTP Streaming, and HTTP server push,
• First implementations appeared in 2000 with Pushlets and LightStreamer media
server
Reverse Ajax
Basic polling techniques
Reverse Ajax – simple polling
Reverse Ajax – simple polling
• Basic Ajax with regular interval requests (every few seconds).
• To get the server events as soon as possible, the polling interval (time between
requests) must be as low as possible.
• If interval is reduced, the client will issue many more requests, many of which
won't return any useful data, and will consume bandwidth and processing
resources for nothing.
• Advantages: It's really easy to implement and does not require any special
features on the server side. It also works in all browsers.
• Disadvantages: This method is rarely employed because it does not scale at all.
Example: 100 clients each issuing polling requests for 2 seconds, where 30% of
the requests returns no data.
Reverse Ajax – piggyback polling
Reverse Ajax – piggyback polling
• Piggyback polling removes all redundant requests (which return no data)
• There is no interval
• Requests are sent when the client needs to send a request to the server
• The difference lies in the response, which is split into two parts:
 the response for the requested data
 server events, if any
• Advantages: Less resource consumption. Works in all browsers, does not
require special features on the server side.
• Disadvantages: You have no clue when the events accumulated on the server
side will be delivered to the client.
Reverse Ajax – Comet
Reverse Ajax – Comet
• Request is sent to the server and kept alive for a long time, until a time-out or
a server event occurs.
• When the request is completed, another long-lived Ajax request is sent to wait
for other server events.
• With Comet, web servers can send the data to the client without having to
explicitly request it.
• The server can push events on the clients by immediately committing
(completing) the responses, or it can accumulate them and send bursts.
• Special features are required on the server side to handle all of these long-lived
requests (Servlet 3.0 or Websockets)
• Implementations of Comet can be separated into two types: those using
streaming mode, and those using long polling.
Reverse Ajax
Comet - Streaming Mode
Comet – Streaming mode
• In streaming mode, one persistent connection is opened
• It requires a way to separate the different responses coming through the same
connection on the client side.
• Technically speaking, two common techniques for streaming include:
 Forever Iframes (hidden Iframes) or
 Multi-part feature of the XMLHttpRequest object used to create Ajax
requests in JavaScript.
Comet – Forever Iframes
• Forever Iframes technique involves a hidden Iframe tag put in the page with its
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
with the JavaScript code inside.
• The iframe content will be appended with this script tag that will get executed.
• Advantages: Simple to implement, and it works in all browsers supporting
iframes.
• Disadvantages: There is no way to implement reliable error handling or to
track the state of the connection, because all connection and data are handled
by the browser through HTML tags. You don't know when the connection is
broken on either side.
Comet – Multi-part XMLHttpRequest
• This technique uses the multi-part flag supported by some browsers (Chrome,
Firefox) on the XMLHttpRequest object.
• An Ajax request is sent and kept open on the server side. Each time an event
comes, a multi-part response is written through the same connection
• On the server side it is required to set up the multi-part request, suspend the
connection and return responses asynchronously (Servlet 3.0)
• Advantages: Only one persistent connection is opened. This is the Comet
technique that saves the most bandwidth usage.
• Disadvantages: The multi-part flag is not supported by all browsers. Some
widely used libraries, such as CometD in Java, reported issues in buffering. For
example, chunks of data (multi-parts) may be buffered and sent only when the
connection is completed or the buffer is full, which can create higher latency
than expected.
Reverse Ajax
Comet - HTTP long polling
Comet - HTTP long polling
• The long polling mode involves techniques that use repeated long-held client
requests.
• When client initiates a connection, it is kept open by the server, and as soon as
an event occurs, the response is committed and the connection is closed.
• New long-polling connection is reopened immediately by the client waiting for
the new events to arrive.
• You can implement HTTP long polling by using
 Script tags
 XMLHttpRequest object.
Comet – Script tags
• Similar to the iframe technique, the goal is to append a script tag in your page
to get the script executed.
• The server will: suspend the connection until an event occurs, send the script
content back to the browser, and then reopen another script tag to get the next
events.
• Advantages: Because it's based on HTML tags, this technique is easy to
implement and works across domains (by default, XMLHttpRequest does not
allow requests on other domains or sub-domains).
• Disadvantages: Similar to the iframe technique, error handling is missing, and
you can't have a state or the ability to interrupt a connection.
Comet - XMLHttpRequest long polling
• Recommended method to implement Comet
• Client opens an Ajax request to the server and waits for the response.
• The server requires specific features on the server side to allow the request to
be suspended (Servlet 3.0).
• As soon as an event occurs, the server sends back the response in the
suspended request and closes it.
• The client then consumes the response and opens a new long-lived Ajax
request to the server.
• On the back end, the code also uses the Servlet 3 API to suspend the request, as
in HTTP streaming, but without multi-part handling.
Comet - XMLHttpRequest long polling
• Advantages: It's easy to implement on the client side with a good error-
handling system and timeout management. This reliable technique also
allows reusing connections on the server side, since connections are not
persistent (a good thing, when you have a lot of clients on your application). It
also works on all browsers; you only make use of the XMLHttpRequest object
by issuing a simple Ajax request.
• Disadvantages: There is no main disadvantage compared to other techniques.
But, like all techniques we've discussed, this one still relies on a stateless HTTP
connection, which requires special features on the server side to be able to
temporarily suspend it.
• Several well-known libraries implement Comet in Java and Javascript:
 DWR
 CometD
 Atmosphere
Reverse Ajax
Libraries
DWR
• DWR – direct web remoting
• Well known library for integration between client-side JS and server-side Java code
• Reverse Ajax Modes
 Early Closing Mode (default, low performance for large number of clients)
 Full Streaming Mode (Not available to IE users)
 Long Polling (best option)
 Piggyback mode
• Advantages: Highly configurable and stable library.
• Disadvantages: Development is slow, Websocket support is uncertain.
Atmosphere
• Atmosphere is a Java technology framework that provides a common API for
using the Comet and WebSocket features of many of the web servers, including
Tomcat, Jetty, GlassFish, Weblogic, Grizzly, JBossWeb, JBoss, and Resin.
• Atmosphere has been around for more than two years, and it is still in active
development. It is used in large web applications such as JIRA
• Advantages: Atmosphere's strength remains on the server side: it provides a
standardized API that covers all of the different solutions and ways to
communicate with WebSockets or Comet.
• Disadvantages: Atmosphere does not use a protocol between the client and
server, like DWR and CometD.
CometD – our choice
• CometD framework is an event-driven communication solution based on HTTP.
It provides a Java server part and a Java client part, plus JavaScript client
libraries based upon jQuery and Dojo.
• It has been around for several years. It supports WebSockets. Reverse Ajax
Mode is implemented with XMLHttpRequest long-polling.
• All of the components communicate through a bus to send notifications and
receive events. All communication is asynchronous.
• Advantages: CometD offers a complete solution, from client and server side, and
also from a standalone Java client to a server. The framework is well-
documented and is easy to use. It supports many features - reconnection,
reliable timeout detection, error handling, low-latency communication ...
• Disadvantages: CometD currently does not support any Servlet 2.5 containers
other than Jetty for Comet (Tomcat), and it does not support Glassfish/Grizzly
WebSocket
Websockets
Overview
Websockets
• WebSockets, which comes from HTML5, is a new technique for bidirectional,
full-duplex communication.
• The connection is opened through a HTTP Upgrade request (HTTP request with
special headers), called a WebSockets handshake.
• The connection is then kept alive, and data is exchanged between both sides
directly.
• Best option for bidirectional communication, future standard
• Supported in Chrome 14+, Firefox 6+, Safari 6+, IE 10+
• Supported on Tomcat 8, JBoss 8, Glassfish 3, Jetty 7
• Supported in CometD along with long polling.
References
IBM Developerworks: Reverse Ajax series
http://www.ibm.com/developerworks/library/wa-reverseajax1/
Javabeat: An introduction to Comet and Reverse Ajax
http://www.javabeat.net/introduction-to-comet-and-reverse-ajax/
DWR: Reverse Ajax
http://directwebremoting.org/dwr/documentation/reverse-ajax/
CometD:
http://docs.cometd.org/reference/
Atmosphere Framework:
http://async-io.org/
References
Oracle: Asynchronous Notifications with Servlet 3.0
http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/async-
servlet/async-servlets.html
Javabeat: Asynchronous Servlet
http://www.javabeat.net/asynchronous-servlet-servlet-3-0/
Google groups: CometD users
https://groups.google.com/forum/#!topic/cometd-users
Wikipedia: Comet
http://en.wikipedia.org/wiki/Comet_(programming)#Implementations

Contenu connexe

Tendances

WebSockets wiith Scala and Play! Framework
WebSockets wiith Scala and Play! FrameworkWebSockets wiith Scala and Play! Framework
WebSockets wiith Scala and Play! FrameworkFabio Tiriticco
 
Realtime web application with java
Realtime web application with javaRealtime web application with java
Realtime web application with javaJeongHun Byeon
 
Spring Boot & WebSocket
Spring Boot & WebSocketSpring Boot & WebSocket
Spring Boot & WebSocketMing-Ying Wu
 
Beyond Breakpoints: A Tour of Dynamic Analysis
Beyond Breakpoints: A Tour of Dynamic AnalysisBeyond Breakpoints: A Tour of Dynamic Analysis
Beyond Breakpoints: A Tour of Dynamic AnalysisFastly
 
[1D1]신개념 N스크린 웹 앱 프레임워크 PARS
[1D1]신개념 N스크린 웹 앱 프레임워크 PARS[1D1]신개념 N스크린 웹 앱 프레임워크 PARS
[1D1]신개념 N스크린 웹 앱 프레임워크 PARSNAVER D2
 
Building Next Generation Real-Time Web Applications using Websockets
Building Next Generation Real-Time Web Applications using WebsocketsBuilding Next Generation Real-Time Web Applications using Websockets
Building Next Generation Real-Time Web Applications using WebsocketsNaresh Chintalcheru
 
Using Websockets with Play!
Using Websockets with Play!Using Websockets with Play!
Using Websockets with Play!Andrew Conner
 
Ruby Proxies for Scale, Performance, and Monitoring - GoGaRuCo - igvita.com
Ruby Proxies for Scale, Performance, and Monitoring - GoGaRuCo - igvita.comRuby Proxies for Scale, Performance, and Monitoring - GoGaRuCo - igvita.com
Ruby Proxies for Scale, Performance, and Monitoring - GoGaRuCo - igvita.comIlya Grigorik
 
Ruby C10K: High Performance Networking - RubyKaigi '09
Ruby C10K: High Performance Networking - RubyKaigi '09Ruby C10K: High Performance Networking - RubyKaigi '09
Ruby C10K: High Performance Networking - RubyKaigi '09Ilya Grigorik
 
GWT Web Socket and data serialization
GWT Web Socket and data serializationGWT Web Socket and data serialization
GWT Web Socket and data serializationGWTcon
 
Solving anything in VCL
Solving anything in VCLSolving anything in VCL
Solving anything in VCLFastly
 
Communication in Python and the C10k problem
Communication in Python and the C10k problemCommunication in Python and the C10k problem
Communication in Python and the C10k problemJose Galarza
 
Writing Portable WebSockets in Java
Writing Portable WebSockets in JavaWriting Portable WebSockets in Java
Writing Portable WebSockets in Javajfarcand
 
Building Real-Time Applications with Android and WebSockets
Building Real-Time Applications with Android and WebSocketsBuilding Real-Time Applications with Android and WebSockets
Building Real-Time Applications with Android and WebSocketsSergi Almar i Graupera
 
0-60 with Goliath: Building High Performance Ruby Web-Services
0-60 with Goliath: Building High Performance Ruby Web-Services0-60 with Goliath: Building High Performance Ruby Web-Services
0-60 with Goliath: Building High Performance Ruby Web-ServicesIlya Grigorik
 
No callbacks, No Threads - Cooperative web servers in Ruby 1.9
No callbacks, No Threads - Cooperative web servers in Ruby 1.9No callbacks, No Threads - Cooperative web servers in Ruby 1.9
No callbacks, No Threads - Cooperative web servers in Ruby 1.9Ilya Grigorik
 
Using Websockets in Play !
Using Websockets in Play !Using Websockets in Play !
Using Websockets in Play !Knoldus Inc.
 
Apache Camel Introduction & What's in the box
Apache Camel Introduction & What's in the boxApache Camel Introduction & What's in the box
Apache Camel Introduction & What's in the boxClaus Ibsen
 
A complete guide to Node.js
A complete guide to Node.jsA complete guide to Node.js
A complete guide to Node.jsPrabin Silwal
 

Tendances (20)

WebSockets wiith Scala and Play! Framework
WebSockets wiith Scala and Play! FrameworkWebSockets wiith Scala and Play! Framework
WebSockets wiith Scala and Play! Framework
 
Realtime web application with java
Realtime web application with javaRealtime web application with java
Realtime web application with java
 
Spring Boot & WebSocket
Spring Boot & WebSocketSpring Boot & WebSocket
Spring Boot & WebSocket
 
Beyond Breakpoints: A Tour of Dynamic Analysis
Beyond Breakpoints: A Tour of Dynamic AnalysisBeyond Breakpoints: A Tour of Dynamic Analysis
Beyond Breakpoints: A Tour of Dynamic Analysis
 
[1D1]신개념 N스크린 웹 앱 프레임워크 PARS
[1D1]신개념 N스크린 웹 앱 프레임워크 PARS[1D1]신개념 N스크린 웹 앱 프레임워크 PARS
[1D1]신개념 N스크린 웹 앱 프레임워크 PARS
 
Building Next Generation Real-Time Web Applications using Websockets
Building Next Generation Real-Time Web Applications using WebsocketsBuilding Next Generation Real-Time Web Applications using Websockets
Building Next Generation Real-Time Web Applications using Websockets
 
Using Websockets with Play!
Using Websockets with Play!Using Websockets with Play!
Using Websockets with Play!
 
Ruby Proxies for Scale, Performance, and Monitoring - GoGaRuCo - igvita.com
Ruby Proxies for Scale, Performance, and Monitoring - GoGaRuCo - igvita.comRuby Proxies for Scale, Performance, and Monitoring - GoGaRuCo - igvita.com
Ruby Proxies for Scale, Performance, and Monitoring - GoGaRuCo - igvita.com
 
Ruby C10K: High Performance Networking - RubyKaigi '09
Ruby C10K: High Performance Networking - RubyKaigi '09Ruby C10K: High Performance Networking - RubyKaigi '09
Ruby C10K: High Performance Networking - RubyKaigi '09
 
GWT Web Socket and data serialization
GWT Web Socket and data serializationGWT Web Socket and data serialization
GWT Web Socket and data serialization
 
Websockets and SockJS, Real time chatting
Websockets and SockJS, Real time chattingWebsockets and SockJS, Real time chatting
Websockets and SockJS, Real time chatting
 
Solving anything in VCL
Solving anything in VCLSolving anything in VCL
Solving anything in VCL
 
Communication in Python and the C10k problem
Communication in Python and the C10k problemCommunication in Python and the C10k problem
Communication in Python and the C10k problem
 
Writing Portable WebSockets in Java
Writing Portable WebSockets in JavaWriting Portable WebSockets in Java
Writing Portable WebSockets in Java
 
Building Real-Time Applications with Android and WebSockets
Building Real-Time Applications with Android and WebSocketsBuilding Real-Time Applications with Android and WebSockets
Building Real-Time Applications with Android and WebSockets
 
0-60 with Goliath: Building High Performance Ruby Web-Services
0-60 with Goliath: Building High Performance Ruby Web-Services0-60 with Goliath: Building High Performance Ruby Web-Services
0-60 with Goliath: Building High Performance Ruby Web-Services
 
No callbacks, No Threads - Cooperative web servers in Ruby 1.9
No callbacks, No Threads - Cooperative web servers in Ruby 1.9No callbacks, No Threads - Cooperative web servers in Ruby 1.9
No callbacks, No Threads - Cooperative web servers in Ruby 1.9
 
Using Websockets in Play !
Using Websockets in Play !Using Websockets in Play !
Using Websockets in Play !
 
Apache Camel Introduction & What's in the box
Apache Camel Introduction & What's in the boxApache Camel Introduction & What's in the box
Apache Camel Introduction & What's in the box
 
A complete guide to Node.js
A complete guide to Node.jsA complete guide to Node.js
A complete guide to Node.js
 

Similaire à Reverse ajax in 2014

IT2255 Web Essentials - Unit V Servlets and Database Connectivity
IT2255 Web Essentials - Unit V Servlets and Database ConnectivityIT2255 Web Essentials - Unit V Servlets and Database Connectivity
IT2255 Web Essentials - Unit V Servlets and Database Connectivitypkaviya
 
Developing Revolutionary Web Applications using Comet and Ajax Push
Developing Revolutionary Web Applications using Comet and Ajax PushDeveloping Revolutionary Web Applications using Comet and Ajax Push
Developing Revolutionary Web Applications using Comet and Ajax PushDoris Chen
 
WEB TECHNOLOGY Unit-3.pptx
WEB TECHNOLOGY Unit-3.pptxWEB TECHNOLOGY Unit-3.pptx
WEB TECHNOLOGY Unit-3.pptxkarthiksmart21
 
Comet / WebSocket Web Applications
Comet / WebSocket Web ApplicationsComet / WebSocket Web Applications
Comet / WebSocket Web ApplicationsCodemotion
 
Ajax & Reverse Ajax Presenation
Ajax & Reverse Ajax PresenationAjax & Reverse Ajax Presenation
Ajax & Reverse Ajax PresenationRishabh Garg
 
wa-cometjava-pdf
wa-cometjava-pdfwa-cometjava-pdf
wa-cometjava-pdfHiroshi Ono
 
Servlet.ppt
Servlet.pptServlet.ppt
Servlet.pptkstalin2
 
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 1...
 Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 1... Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 1...
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 1...WebStackAcademy
 
Server side push in Aldan 3
Server side push in Aldan 3Server side push in Aldan 3
Server side push in Aldan 3ALDAN3
 
HTTP/2 Comes to Java: Servlet 4.0 and what it means for the Java/Jakarta EE e...
HTTP/2 Comes to Java: Servlet 4.0 and what it means for the Java/Jakarta EE e...HTTP/2 Comes to Java: Servlet 4.0 and what it means for the Java/Jakarta EE e...
HTTP/2 Comes to Java: Servlet 4.0 and what it means for the Java/Jakarta EE e...Edward Burns
 
Servlet and JSP
Servlet and JSPServlet and JSP
Servlet and JSPGary Yeh
 
Meetup #4: AWS ELB Deep dive & Best practices
Meetup #4: AWS ELB Deep dive & Best practicesMeetup #4: AWS ELB Deep dive & Best practices
Meetup #4: AWS ELB Deep dive & Best practicesAWS Vietnam Community
 

Similaire à Reverse ajax in 2014 (20)

Servlet.pptx
Servlet.pptxServlet.pptx
Servlet.pptx
 
Servlet.pptx
Servlet.pptxServlet.pptx
Servlet.pptx
 
IT2255 Web Essentials - Unit V Servlets and Database Connectivity
IT2255 Web Essentials - Unit V Servlets and Database ConnectivityIT2255 Web Essentials - Unit V Servlets and Database Connectivity
IT2255 Web Essentials - Unit V Servlets and Database Connectivity
 
Developing Revolutionary Web Applications using Comet and Ajax Push
Developing Revolutionary Web Applications using Comet and Ajax PushDeveloping Revolutionary Web Applications using Comet and Ajax Push
Developing Revolutionary Web Applications using Comet and Ajax Push
 
WEB TECHNOLOGY Unit-3.pptx
WEB TECHNOLOGY Unit-3.pptxWEB TECHNOLOGY Unit-3.pptx
WEB TECHNOLOGY Unit-3.pptx
 
Comet / WebSocket Web Applications
Comet / WebSocket Web ApplicationsComet / WebSocket Web Applications
Comet / WebSocket Web Applications
 
Ajax & Reverse Ajax Presenation
Ajax & Reverse Ajax PresenationAjax & Reverse Ajax Presenation
Ajax & Reverse Ajax Presenation
 
wa-cometjava-pdf
wa-cometjava-pdfwa-cometjava-pdf
wa-cometjava-pdf
 
Servlet.ppt
Servlet.pptServlet.ppt
Servlet.ppt
 
Servlet.ppt
Servlet.pptServlet.ppt
Servlet.ppt
 
Servlet1.ppt
Servlet1.pptServlet1.ppt
Servlet1.ppt
 
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 1...
 Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 1... Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 1...
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 1...
 
Web-Socket
Web-SocketWeb-Socket
Web-Socket
 
Server side push in Aldan 3
Server side push in Aldan 3Server side push in Aldan 3
Server side push in Aldan 3
 
HTTP/2 Comes to Java: Servlet 4.0 and what it means for the Java/Jakarta EE e...
HTTP/2 Comes to Java: Servlet 4.0 and what it means for the Java/Jakarta EE e...HTTP/2 Comes to Java: Servlet 4.0 and what it means for the Java/Jakarta EE e...
HTTP/2 Comes to Java: Servlet 4.0 and what it means for the Java/Jakarta EE e...
 
JAVA
JAVAJAVA
JAVA
 
Servlet and JSP
Servlet and JSPServlet and JSP
Servlet and JSP
 
Ecom 1
Ecom 1Ecom 1
Ecom 1
 
jQuery Ajax
jQuery AjaxjQuery Ajax
jQuery Ajax
 
Meetup #4: AWS ELB Deep dive & Best practices
Meetup #4: AWS ELB Deep dive & Best practicesMeetup #4: AWS ELB Deep dive & Best practices
Meetup #4: AWS ELB Deep dive & Best practices
 

Dernier

Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 

Dernier (20)

Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 

Reverse ajax in 2014

  • 2. Ajax (Asynchronous JavaScript and XML) • Group of interrelated Web development techniques used on the client-side to create asynchronous Web applications. • With Ajax, Web applications can send data to, and retrieve data from a server asynchronously (in the background) without the need for a page reload. • It is a browser feature accessible to a web page through the JavaScript. • Though the name includes XML, nearly anything can be transfered with an Ajax request. • The most commonly used data is JSON, which is close to JavaScript syntax and consumes less bandwidth. • Ajax requests are stateless by default, and can only be opened from the client to the server.
  • 3. Reverse Ajax • Reverse Ajax is essentially a concept for sending data from the server to the client. • It can be simulated with a repeated Ajax request from client – simple polling, piggyback polling. • Comet – umbrella term for various techniques for Reverse Ajax • Coined by Alex Russel in 2006. • It can be simulated with a long-held Ajax request from client . • Server can send events to the client without the client specifically requesting it. • Also known as Ajax Push, Two-way-web, HTTP Streaming, and HTTP server push, • First implementations appeared in 2000 with Pushlets and LightStreamer media server
  • 5. Reverse Ajax – simple polling
  • 6. Reverse Ajax – simple polling • Basic Ajax with regular interval requests (every few seconds). • To get the server events as soon as possible, the polling interval (time between requests) must be as low as possible. • If interval is reduced, the client will issue many more requests, many of which won't return any useful data, and will consume bandwidth and processing resources for nothing. • Advantages: It's really easy to implement and does not require any special features on the server side. It also works in all browsers. • Disadvantages: This method is rarely employed because it does not scale at all. Example: 100 clients each issuing polling requests for 2 seconds, where 30% of the requests returns no data.
  • 7. Reverse Ajax – piggyback polling
  • 8. Reverse Ajax – piggyback polling • Piggyback polling removes all redundant requests (which return no data) • There is no interval • Requests are sent when the client needs to send a request to the server • The difference lies in the response, which is split into two parts:  the response for the requested data  server events, if any • Advantages: Less resource consumption. Works in all browsers, does not require special features on the server side. • Disadvantages: You have no clue when the events accumulated on the server side will be delivered to the client.
  • 10. Reverse Ajax – Comet • Request is sent to the server and kept alive for a long time, until a time-out or a server event occurs. • When the request is completed, another long-lived Ajax request is sent to wait for other server events. • With Comet, web servers can send the data to the client without having to explicitly request it. • The server can push events on the clients by immediately committing (completing) the responses, or it can accumulate them and send bursts. • Special features are required on the server side to handle all of these long-lived requests (Servlet 3.0 or Websockets) • Implementations of Comet can be separated into two types: those using streaming mode, and those using long polling.
  • 11. Reverse Ajax Comet - Streaming Mode
  • 12. Comet – Streaming mode • In streaming mode, one persistent connection is opened • It requires a way to separate the different responses coming through the same connection on the client side. • Technically speaking, two common techniques for streaming include:  Forever Iframes (hidden Iframes) or  Multi-part feature of the XMLHttpRequest object used to create Ajax requests in JavaScript.
  • 13. Comet – Forever Iframes • Forever Iframes technique involves a hidden Iframe tag put in the page with its 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 with the JavaScript code inside. • The iframe content will be appended with this script tag that will get executed. • Advantages: Simple to implement, and it works in all browsers supporting iframes. • Disadvantages: There is no way to implement reliable error handling or to track the state of the connection, because all connection and data are handled by the browser through HTML tags. You don't know when the connection is broken on either side.
  • 14. Comet – Multi-part XMLHttpRequest • This technique uses the multi-part flag supported by some browsers (Chrome, Firefox) on the XMLHttpRequest object. • An Ajax request is sent and kept open on the server side. Each time an event comes, a multi-part response is written through the same connection • On the server side it is required to set up the multi-part request, suspend the connection and return responses asynchronously (Servlet 3.0) • Advantages: Only one persistent connection is opened. This is the Comet technique that saves the most bandwidth usage. • Disadvantages: The multi-part flag is not supported by all browsers. Some widely used libraries, such as CometD in Java, reported issues in buffering. For example, chunks of data (multi-parts) may be buffered and sent only when the connection is completed or the buffer is full, which can create higher latency than expected.
  • 15. Reverse Ajax Comet - HTTP long polling
  • 16. Comet - HTTP long polling • The long polling mode involves techniques that use repeated long-held client requests. • When client initiates a connection, it is kept open by the server, and as soon as an event occurs, the response is committed and the connection is closed. • New long-polling connection is reopened immediately by the client waiting for the new events to arrive. • You can implement HTTP long polling by using  Script tags  XMLHttpRequest object.
  • 17. Comet – Script tags • Similar to the iframe technique, the goal is to append a script tag in your page to get the script executed. • The server will: suspend the connection until an event occurs, send the script content back to the browser, and then reopen another script tag to get the next events. • Advantages: Because it's based on HTML tags, this technique is easy to implement and works across domains (by default, XMLHttpRequest does not allow requests on other domains or sub-domains). • Disadvantages: Similar to the iframe technique, error handling is missing, and you can't have a state or the ability to interrupt a connection.
  • 18. Comet - XMLHttpRequest long polling • Recommended method to implement Comet • Client opens an Ajax request to the server and waits for the response. • The server requires specific features on the server side to allow the request to be suspended (Servlet 3.0). • As soon as an event occurs, the server sends back the response in the suspended request and closes it. • The client then consumes the response and opens a new long-lived Ajax request to the server. • On the back end, the code also uses the Servlet 3 API to suspend the request, as in HTTP streaming, but without multi-part handling.
  • 19. Comet - XMLHttpRequest long polling • Advantages: It's easy to implement on the client side with a good error- handling system and timeout management. This reliable technique also allows reusing connections on the server side, since connections are not persistent (a good thing, when you have a lot of clients on your application). It also works on all browsers; you only make use of the XMLHttpRequest object by issuing a simple Ajax request. • Disadvantages: There is no main disadvantage compared to other techniques. But, like all techniques we've discussed, this one still relies on a stateless HTTP connection, which requires special features on the server side to be able to temporarily suspend it. • Several well-known libraries implement Comet in Java and Javascript:  DWR  CometD  Atmosphere
  • 21. DWR • DWR – direct web remoting • Well known library for integration between client-side JS and server-side Java code • Reverse Ajax Modes  Early Closing Mode (default, low performance for large number of clients)  Full Streaming Mode (Not available to IE users)  Long Polling (best option)  Piggyback mode • Advantages: Highly configurable and stable library. • Disadvantages: Development is slow, Websocket support is uncertain.
  • 22. Atmosphere • Atmosphere is a Java technology framework that provides a common API for using the Comet and WebSocket features of many of the web servers, including Tomcat, Jetty, GlassFish, Weblogic, Grizzly, JBossWeb, JBoss, and Resin. • Atmosphere has been around for more than two years, and it is still in active development. It is used in large web applications such as JIRA • Advantages: Atmosphere's strength remains on the server side: it provides a standardized API that covers all of the different solutions and ways to communicate with WebSockets or Comet. • Disadvantages: Atmosphere does not use a protocol between the client and server, like DWR and CometD.
  • 23. CometD – our choice • CometD framework is an event-driven communication solution based on HTTP. It provides a Java server part and a Java client part, plus JavaScript client libraries based upon jQuery and Dojo. • It has been around for several years. It supports WebSockets. Reverse Ajax Mode is implemented with XMLHttpRequest long-polling. • All of the components communicate through a bus to send notifications and receive events. All communication is asynchronous. • Advantages: CometD offers a complete solution, from client and server side, and also from a standalone Java client to a server. The framework is well- documented and is easy to use. It supports many features - reconnection, reliable timeout detection, error handling, low-latency communication ... • Disadvantages: CometD currently does not support any Servlet 2.5 containers other than Jetty for Comet (Tomcat), and it does not support Glassfish/Grizzly WebSocket
  • 25. Websockets • WebSockets, which comes from HTML5, is a new technique for bidirectional, full-duplex communication. • The connection is opened through a HTTP Upgrade request (HTTP request with special headers), called a WebSockets handshake. • The connection is then kept alive, and data is exchanged between both sides directly. • Best option for bidirectional communication, future standard • Supported in Chrome 14+, Firefox 6+, Safari 6+, IE 10+ • Supported on Tomcat 8, JBoss 8, Glassfish 3, Jetty 7 • Supported in CometD along with long polling.
  • 26. References IBM Developerworks: Reverse Ajax series http://www.ibm.com/developerworks/library/wa-reverseajax1/ Javabeat: An introduction to Comet and Reverse Ajax http://www.javabeat.net/introduction-to-comet-and-reverse-ajax/ DWR: Reverse Ajax http://directwebremoting.org/dwr/documentation/reverse-ajax/ CometD: http://docs.cometd.org/reference/ Atmosphere Framework: http://async-io.org/
  • 27. References Oracle: Asynchronous Notifications with Servlet 3.0 http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/async- servlet/async-servlets.html Javabeat: Asynchronous Servlet http://www.javabeat.net/asynchronous-servlet-servlet-3-0/ Google groups: CometD users https://groups.google.com/forum/#!topic/cometd-users Wikipedia: Comet http://en.wikipedia.org/wiki/Comet_(programming)#Implementations