Asynchronous Web
Programming with HTML5
WebSockets and Java
James Falkner
Community Manager, Liferay, Inc.
james.falkner@liferay.com
@schtool
The Asynchronous World
The Asynchronous Word
• Literally: Without Time
• Events that occur outside of the main program
execution flow
• Asynchronous != parallel/multi-threading
Execution Models
Execution Models
Single-Threaded Synchronous Model
• Not much to say here
Execution Models
Threaded Model
• CPU controls interleaving
• Developer must
coordinate
threads/processes
• “preemptive multitasking”
Execution Models
Asynchronous Model
• Developer controls interleaving
• “cooperative multitasking”
• Wave goodbye to race conditions,
synchronized, and deadlocks!
• Windows 3.x, MacOS 9.x, Space
Shuttle
Execution Models
The green code (your code!)
runs uninterrupted until it
(you!) reaches a “good
stopping point”
(I/O)
What does this buy me?
NOTHING! Except when
• Task Pool is large
• Task I/O >> Task CPU
• Tasks mostly independent
… Like web servers
Asynchronous Web Programming with HTML5 WebSockets and Java
Programming Models
Threaded vs. Event-Driven
while (true) {
client = accept(80);
/* blocked! */
new Thread(new Handler(client)).start();
}
vs.
new Server(80, {
onConnect: {
handler.handle(client);
}
});
/* no blocking here, move along */
Threaded vs. Event-Driven
• Both can solve the exact same set of problems
• In fact, they are semantically equivalent
• Threaded costs in complexity and context
switching
• Event-Driven costs in complexity and no
context switching
Forces
• When to consider event-driven, asynchronous
programming models?
Async/Eventing Support
• Hardware/OS: Interrupts, select(), etc
• Languages: callbacks, closures, futures,
promises, Reactor/IOU pattern
• All accomplish the same thing: do this thing
for me, and when you’re done, do this other
dependent thing
• Frameworks
• Makes async/event programming possible or
easier
• JavaEE, Play, Vert.x, Cramp, node.js,
Twisted, …
Reducing Complexity
• Use established patterns
• Use established libraries and tooling
https://github.com/caolan/async
Typical Evented Web Apps
Event-Driven Java/JavaEE
• Java 1.0: Threads and AWT
• Java 1.4: NIO (Non-blocking I/O, nee New I/O)
• J2EE 1.2: JMS
• JavaEE 6: @Asynchronous and CDI
JavaEE 7: WebSockets
• Future: Lambda Expressions (closures)
myButton.addActionListener(ae -> {
System.out.println(ae.getSource());
});
Early Event-Driven Java
• Closure-like listeners (e.g. addActionListener(), handlers)
• Captured “free” variables must be final
• Hogging CPU in listener is bad
• References to this and OuterClass.this
Event-Driven JavaEE
• Servlet 3.0
• Async servlets
• JAX-RS (Jersey)
• Client Async API (via Futures/callbacks)
• Server Async HTTP Requests
• JMS
• Message Redelivery, QoS, scalability, …
• CDI/EJB
• Via @Inject, @Asynchronous and @Observes
JavaEE Example: Event
Definition
public class HelloEvent {
private String msg;
public HelloEvent(String msg) {
msg = msg;
}
public String getMessage() {
return message;
}
}
JavaEE Example: Event
Subscriber
@Stateless
public class HelloListener {
@Asynchronous
public void listen(@Observes HelloEvent helloEvent){
System.out.println("HelloEvent: " + helloEvent);
}
}
JavaEE Example: Event Publish
@Named("messenger”)
@Stateless
public class HelloMessenger {
@Inject Event<HelloEvent> events;
public void hello() {
events.fire(new HelloEvent("from bean " +
System.currentTimeMillis()));
}
}
<h:commandButton
value="Fire!"
action="#{messenger.hello}"/>
JavaEE Example: Async Servlet
JavaEE Example: Async Servlet
Event-Driven Framework: Vert.x
Event-Driven JavaScript
• Not just for the browser
anymore
• It’s cool to like it! (again)
• Language features greatly
aid event-driven
programming
• Many, many frameworks to
aid in better design
The Asynchronous Web
• Goal: Responsive, Interactive sites
• Technique: Push or Pull
• First: Pull
• Request/Response
• AJAX Pull/Poll
• Now: Push
• Long Polling
• Proprietary (e.g. Flash)
• Server-Sent Events (nee HTTP Streaming)
• WebSockets
Asynchronous Web Programming with HTML5 WebSockets and Java
WebSockets
• Bi-directional, full-duplex TCP connection
• Asynchronous APIs
• Related Standards
• Protocol: IETF RFC 6455
• Browser API: W3C WebSockets JavaScript
API
• Client/Server API: JSR-356 (Java)
• 50+ Implementations, 15+ Languages
• Java, C#, PHP, Python, C/C++, Node, …
Wire Protocol
Wire Protocol
Wire Protocol
• FIN
• Indicates the last frame of a message
• RSV[1-3]
• 0, or extension-specific
• OPCODE
• Frame identifier (continuation, text, close, etc)
• MASK
• Whether the frame is masked
• PAYLOAD LEN
• Length of data
• PAYLOAD DATA
• Extension Data + Application Data
WebSockets Options
• Endpoint identification
• Version negotiation
• Protocol Extensions negotiation
• Application Sub-protocol negotiation
• Security options
Handshake
Java Server API (JSR-356)
• Endpoints represent client/server connection
• Sessions model set of interactions over
Endpoint
• sync/async messages
• Injection
• Custom encoding/decoding
• Configuration options mirror wire protocol
• Binary/Text
• PathParam
• Extensions
Java Server API
@ServerEndpoint("/websocket")
public class MyEndpoint {
private Session session;
@OnOpen
public void open(Session session) {
this.session = session;
}
@OnMessage
public String echoText(String msg) {
return msg;
}
@OnClose
…
@OnError
…
public void sendSomething() {
session.getAsyncRemote()
.sendText(“Boo!”);
}
Client API (JavaScript)
var ws = new WebSocket('ws://host:port/endpoint');
ws.onmessage = function (event) {
console.log('Received text from the server: ' + event.data);
// do something with it
};
ws.onerror = function(event) {
console. log("Uh oh");
};
ws.onopen = function(event) {
// Here we know connection is established,
// so enable the UI to start sending!
};
ws.onclose = function(event) {
// Here the connection is closing (e.g. user is leaving page),
// so stop sending stuff.
};
Client API (Other)
• Non-Browser APIs for C/C++, Java, .NET, Perl,
PHP, Python, C#, and probably others
WebSocket webSocketClient =
new WebSocket("ws://127.0.0.1:911/websocket", "basic");
webSocketClient.OnClose += new EventHandler(webSocketClient_OnClose);
webSocketClient.OnMessage += new
EventHandler<MessageEventArgs>(webSocketClient_OnMessage);
webSocketClient.Connect());
webSocketClient.Send(“HELLO THERE SERVER!”);
webSocketClient.Close();
Browser Support
• Your users don’t care about WebSockets
• Fallback support: jQuery, Vaadin, Atmosphere,
Socket.IO, Play, etc
Asynchronous Web Programming with HTML5 WebSockets and Java
Demo
WebSocket
ServerEndpoint
JVM
HTTP
WS
Demo Part Deux
WebSocket
ServerEndpoint
JVM
Node
HTTP
HTTP
WS
WebSocket Gotchas
• Using WebSockets in a thread-based system
(e.g. the JVM)
• Sending or receiving data before connection is
established, re-establishing connections
• UTF-8 Encoding
• Extensions, security, masking make debugging
more challenging
WebSocket Issues
• Ephemeral Port Exhaustion
• Evolving interfaces
• Misbehaving Proxies
Acknowledgements
http://cs.brown.edu/courses/cs168/f12/handouts/async.pdf (Execution Models)
http://www.infosecisland.com/blogview/12681-The-WebSocket-Protocol-Past-Travails-To-Be-Avoided.html (problems)
http://lucumr.pocoo.org/2012/9/24/websockets-101/ (more problems)
http://wmarkito.wordpress.com/2012/07/20/cdi-events-synchronous-x-asynchronous/ (cdi examples)
http://blog.arungupta.me/2010/05/totd-139-asynchronous-request-processing-using-servlets-3-0-and-java-ee-6/ (async
servlets)
http://vertx.io (vert.x example)
https://cwiki.apache.org/TUSCANYWIKI/develop-websocket-binding-for-apache-tuscany.html (handshake image)
http://caniuse.com/websockets (browser compat graph)
Asynchronous Web
Programming with HTML5
WebSockets and Java
James Falkner
Community Manager, Liferay, Inc.
james.falkner@liferay.com
@schtool

More Related Content

PDF
HIẾU KINH - KHỔNG TỪ
PDF
Toan 9 cac-dang-toan-on-thi-vao-10
PDF
Cross-domain requests with CORS
PDF
CamundaCon 2018: Using Zeebe with Spring Boot and Apache Camel (Holisticon)
PDF
Comparing Sidecar-less Service Mesh from Cilium and Istio
PDF
Security Bootcamp 2013 - OWASP TOP 10- 2013
DOCX
Chú Đại Bi
PDF
20190330 RxFlow 시작하기
HIẾU KINH - KHỔNG TỪ
Toan 9 cac-dang-toan-on-thi-vao-10
Cross-domain requests with CORS
CamundaCon 2018: Using Zeebe with Spring Boot and Apache Camel (Holisticon)
Comparing Sidecar-less Service Mesh from Cilium and Istio
Security Bootcamp 2013 - OWASP TOP 10- 2013
Chú Đại Bi
20190330 RxFlow 시작하기

What's hot (12)

PDF
Ngọc Hoàng Kinh_v2
PDF
Hoang mau huan tu thap gioi
PDF
[Luật chơi] Bears vs babies - Đầu gấu đấu trẻ con
PDF
Giáo trình ngôn ngữ mô hình hóa UML - Trường ĐH Cần Thơ.pdf
PDF
Manual basico batista_nacional
DOCX
Dang so
PDF
[BoardgameVN] Luật chơi Sushi Go!
PDF
[Hebemart.vn] Nuoi Con Khong Phai La Cuoc Chien Tap 1.pdf
PDF
Quan thánh đế quân giác thế chân kinh
PDF
[BoardgameVN] Luật chơi Da Vinci Code
PDF
Battle of the frameworks : Quarkus vs SpringBoot
Ngọc Hoàng Kinh_v2
Hoang mau huan tu thap gioi
[Luật chơi] Bears vs babies - Đầu gấu đấu trẻ con
Giáo trình ngôn ngữ mô hình hóa UML - Trường ĐH Cần Thơ.pdf
Manual basico batista_nacional
Dang so
[BoardgameVN] Luật chơi Sushi Go!
[Hebemart.vn] Nuoi Con Khong Phai La Cuoc Chien Tap 1.pdf
Quan thánh đế quân giác thế chân kinh
[BoardgameVN] Luật chơi Da Vinci Code
Battle of the frameworks : Quarkus vs SpringBoot
Ad

Viewers also liked (20)

PDF
Building Next Generation Real-Time Web Applications using Websockets
PDF
Realtime web application with java
PDF
Testing concurrent java programs - Sameer Arora
PPT
JUG louvain websockets
PDF
Servlet Async I/O Proposal (NIO.2)
PPTX
Enhancing Mobile User Experience with WebSocket
PPTX
V2 peter-lubbers-sf-jug-websocket
PPTX
Think async
DOCX
Quize on scripting shell
PDF
Shell Scripting With Arguments
PDF
Part 5 of "Introduction to Linux for Bioinformatics": Working the command lin...
PDF
Cloud Foundry Summit 2015: Cloud Foundry and IoT Protocol Support
PPTX
Introduction to WebSockets
PPTX
Bash Shell Scripting
PDF
Introduction to node js - From "hello world" to deploying on azure
PPT
Shell Scripting
PPT
Bash shell
PDF
From Push Technology to Real-Time Messaging and WebSockets
PPT
Unix Shell Scripting Basics
PPTX
Serverless Data Architecture at scale on Google Cloud Platform - Lorenzo Ridi...
Building Next Generation Real-Time Web Applications using Websockets
Realtime web application with java
Testing concurrent java programs - Sameer Arora
JUG louvain websockets
Servlet Async I/O Proposal (NIO.2)
Enhancing Mobile User Experience with WebSocket
V2 peter-lubbers-sf-jug-websocket
Think async
Quize on scripting shell
Shell Scripting With Arguments
Part 5 of "Introduction to Linux for Bioinformatics": Working the command lin...
Cloud Foundry Summit 2015: Cloud Foundry and IoT Protocol Support
Introduction to WebSockets
Bash Shell Scripting
Introduction to node js - From "hello world" to deploying on azure
Shell Scripting
Bash shell
From Push Technology to Real-Time Messaging and WebSockets
Unix Shell Scripting Basics
Serverless Data Architecture at scale on Google Cloud Platform - Lorenzo Ridi...
Ad

Similar to Asynchronous Web Programming with HTML5 WebSockets and Java (20)

PDF
Con fess 2013-sse-websockets-json-bhakti
PDF
Java EE 7 (Lyon JUG & Alpes JUG - March 2014)
PDF
Getting Started with WebSocket and Server-Sent Events using Java by Arun Gupta
PDF
Getting started with Websocket and Server-sent Events using Java - Arun Gupta
PDF
Getting Started with WebSocket and Server-Sent Events in Java
PDF
WebSockets - Realtime em Mundo Conectado
PDF
Web Technologies in Java EE 7
ODP
Server Sent Events, Async Servlet, Web Sockets and JSON; born to work together!
PDF
Getting Started with WebSockets and Server-Sent Events
PDF
Getting Started with WebSocket and Server-Sent Events using Java - Arun Gupta...
PDF
WebSocket in Enterprise Applications 2015
PDF
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 1...
PPTX
JUDCon 2013- JBoss Data Grid and WebSockets: Delivering Real Time Push at Scale
PDF
Java API for WebSocket 1.0: Java EE 7 and GlassFish
PPTX
WebSockets in JEE 7
PDF
Lecture 6 Web Sockets
PPT
Don't Wait! Develop responsive applications with Java EE7 instead
KEY
A language for the Internet: Why JavaScript and Node.js is right for Internet...
ODP
Polling Techniques, Ajax, protocol Switching from Http to Websocket standard ...
Con fess 2013-sse-websockets-json-bhakti
Java EE 7 (Lyon JUG & Alpes JUG - March 2014)
Getting Started with WebSocket and Server-Sent Events using Java by Arun Gupta
Getting started with Websocket and Server-sent Events using Java - Arun Gupta
Getting Started with WebSocket and Server-Sent Events in Java
WebSockets - Realtime em Mundo Conectado
Web Technologies in Java EE 7
Server Sent Events, Async Servlet, Web Sockets and JSON; born to work together!
Getting Started with WebSockets and Server-Sent Events
Getting Started with WebSocket and Server-Sent Events using Java - Arun Gupta...
WebSocket in Enterprise Applications 2015
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 1...
JUDCon 2013- JBoss Data Grid and WebSockets: Delivering Real Time Push at Scale
Java API for WebSocket 1.0: Java EE 7 and GlassFish
WebSockets in JEE 7
Lecture 6 Web Sockets
Don't Wait! Develop responsive applications with Java EE7 instead
A language for the Internet: Why JavaScript and Node.js is right for Internet...
Polling Techniques, Ajax, protocol Switching from Http to Websocket standard ...

Recently uploaded (20)

PDF
FASHION-DRIVEN TEXTILES AS A CRYSTAL OF A NEW STREAM FOR STAKEHOLDER CAPITALI...
PDF
ment.tech-Siri Delay Opens AI Startup Opportunity in 2025.pdf
PPTX
Slides World Game (s) Great Redesign Eco Economic Epochs.pptx
PDF
TicketRoot: Event Tech Solutions Deck 2025
PDF
Decision Optimization - From Theory to Practice
PPTX
From Curiosity to ROI — Cost-Benefit Analysis of Agentic Automation [3/6]
PDF
Introduction to c language from lecture slides
PDF
The Digital Engine Room: Unlocking APAC’s Economic and Digital Potential thro...
PDF
“Introduction to Designing with AI Agents,” a Presentation from Amazon Web Se...
PPTX
From XAI to XEE through Influence and Provenance.Controlling model fairness o...
PDF
EGCB_Solar_Project_Presentation_and Finalcial Analysis.pdf
PDF
Ebook - The Future of AI A Comprehensive Guide.pdf
PDF
CCUS-as-the-Missing-Link-to-Net-Zero_AksCurious.pdf
PPT
Overviiew on Intellectual property right
PPTX
Presentation - Principles of Instructional Design.pptx
PPTX
Rise of the Digital Control Grid Zeee Media and Hope and Tivon FTWProject.com
PDF
Chapter 1: computer maintenance and troubleshooting
PPTX
CRM(Customer Relationship Managmnet) Presentation
PPTX
Build automations faster and more reliably with UiPath ScreenPlay
PPTX
maintenance powerrpoint for adaprive and preventive
FASHION-DRIVEN TEXTILES AS A CRYSTAL OF A NEW STREAM FOR STAKEHOLDER CAPITALI...
ment.tech-Siri Delay Opens AI Startup Opportunity in 2025.pdf
Slides World Game (s) Great Redesign Eco Economic Epochs.pptx
TicketRoot: Event Tech Solutions Deck 2025
Decision Optimization - From Theory to Practice
From Curiosity to ROI — Cost-Benefit Analysis of Agentic Automation [3/6]
Introduction to c language from lecture slides
The Digital Engine Room: Unlocking APAC’s Economic and Digital Potential thro...
“Introduction to Designing with AI Agents,” a Presentation from Amazon Web Se...
From XAI to XEE through Influence and Provenance.Controlling model fairness o...
EGCB_Solar_Project_Presentation_and Finalcial Analysis.pdf
Ebook - The Future of AI A Comprehensive Guide.pdf
CCUS-as-the-Missing-Link-to-Net-Zero_AksCurious.pdf
Overviiew on Intellectual property right
Presentation - Principles of Instructional Design.pptx
Rise of the Digital Control Grid Zeee Media and Hope and Tivon FTWProject.com
Chapter 1: computer maintenance and troubleshooting
CRM(Customer Relationship Managmnet) Presentation
Build automations faster and more reliably with UiPath ScreenPlay
maintenance powerrpoint for adaprive and preventive

Asynchronous Web Programming with HTML5 WebSockets and Java

  • 1. Asynchronous Web Programming with HTML5 WebSockets and Java James Falkner Community Manager, Liferay, Inc. [email protected] @schtool
  • 3. The Asynchronous Word • Literally: Without Time • Events that occur outside of the main program execution flow • Asynchronous != parallel/multi-threading
  • 5. Execution Models Single-Threaded Synchronous Model • Not much to say here
  • 6. Execution Models Threaded Model • CPU controls interleaving • Developer must coordinate threads/processes • “preemptive multitasking”
  • 7. Execution Models Asynchronous Model • Developer controls interleaving • “cooperative multitasking” • Wave goodbye to race conditions, synchronized, and deadlocks! • Windows 3.x, MacOS 9.x, Space Shuttle
  • 8. Execution Models The green code (your code!) runs uninterrupted until it (you!) reaches a “good stopping point” (I/O)
  • 9. What does this buy me? NOTHING! Except when • Task Pool is large • Task I/O >> Task CPU • Tasks mostly independent … Like web servers
  • 12. Threaded vs. Event-Driven while (true) { client = accept(80); /* blocked! */ new Thread(new Handler(client)).start(); } vs. new Server(80, { onConnect: { handler.handle(client); } }); /* no blocking here, move along */
  • 13. Threaded vs. Event-Driven • Both can solve the exact same set of problems • In fact, they are semantically equivalent • Threaded costs in complexity and context switching • Event-Driven costs in complexity and no context switching
  • 14. Forces • When to consider event-driven, asynchronous programming models?
  • 15. Async/Eventing Support • Hardware/OS: Interrupts, select(), etc • Languages: callbacks, closures, futures, promises, Reactor/IOU pattern • All accomplish the same thing: do this thing for me, and when you’re done, do this other dependent thing • Frameworks • Makes async/event programming possible or easier • JavaEE, Play, Vert.x, Cramp, node.js, Twisted, …
  • 16. Reducing Complexity • Use established patterns • Use established libraries and tooling https://github.com/caolan/async
  • 18. Event-Driven Java/JavaEE • Java 1.0: Threads and AWT • Java 1.4: NIO (Non-blocking I/O, nee New I/O) • J2EE 1.2: JMS • JavaEE 6: @Asynchronous and CDI JavaEE 7: WebSockets • Future: Lambda Expressions (closures) myButton.addActionListener(ae -> { System.out.println(ae.getSource()); });
  • 19. Early Event-Driven Java • Closure-like listeners (e.g. addActionListener(), handlers) • Captured “free” variables must be final • Hogging CPU in listener is bad • References to this and OuterClass.this
  • 20. Event-Driven JavaEE • Servlet 3.0 • Async servlets • JAX-RS (Jersey) • Client Async API (via Futures/callbacks) • Server Async HTTP Requests • JMS • Message Redelivery, QoS, scalability, … • CDI/EJB • Via @Inject, @Asynchronous and @Observes
  • 21. JavaEE Example: Event Definition public class HelloEvent { private String msg; public HelloEvent(String msg) { msg = msg; } public String getMessage() { return message; } }
  • 22. JavaEE Example: Event Subscriber @Stateless public class HelloListener { @Asynchronous public void listen(@Observes HelloEvent helloEvent){ System.out.println("HelloEvent: " + helloEvent); } }
  • 23. JavaEE Example: Event Publish @Named("messenger”) @Stateless public class HelloMessenger { @Inject Event<HelloEvent> events; public void hello() { events.fire(new HelloEvent("from bean " + System.currentTimeMillis())); } } <h:commandButton value="Fire!" action="#{messenger.hello}"/>
  • 27. Event-Driven JavaScript • Not just for the browser anymore • It’s cool to like it! (again) • Language features greatly aid event-driven programming • Many, many frameworks to aid in better design
  • 28. The Asynchronous Web • Goal: Responsive, Interactive sites • Technique: Push or Pull • First: Pull • Request/Response • AJAX Pull/Poll • Now: Push • Long Polling • Proprietary (e.g. Flash) • Server-Sent Events (nee HTTP Streaming) • WebSockets
  • 30. WebSockets • Bi-directional, full-duplex TCP connection • Asynchronous APIs • Related Standards • Protocol: IETF RFC 6455 • Browser API: W3C WebSockets JavaScript API • Client/Server API: JSR-356 (Java) • 50+ Implementations, 15+ Languages • Java, C#, PHP, Python, C/C++, Node, …
  • 33. Wire Protocol • FIN • Indicates the last frame of a message • RSV[1-3] • 0, or extension-specific • OPCODE • Frame identifier (continuation, text, close, etc) • MASK • Whether the frame is masked • PAYLOAD LEN • Length of data • PAYLOAD DATA • Extension Data + Application Data
  • 34. WebSockets Options • Endpoint identification • Version negotiation • Protocol Extensions negotiation • Application Sub-protocol negotiation • Security options
  • 36. Java Server API (JSR-356) • Endpoints represent client/server connection • Sessions model set of interactions over Endpoint • sync/async messages • Injection • Custom encoding/decoding • Configuration options mirror wire protocol • Binary/Text • PathParam • Extensions
  • 37. Java Server API @ServerEndpoint("/websocket") public class MyEndpoint { private Session session; @OnOpen public void open(Session session) { this.session = session; } @OnMessage public String echoText(String msg) { return msg; } @OnClose … @OnError … public void sendSomething() { session.getAsyncRemote() .sendText(“Boo!”); }
  • 38. Client API (JavaScript) var ws = new WebSocket('ws://host:port/endpoint'); ws.onmessage = function (event) { console.log('Received text from the server: ' + event.data); // do something with it }; ws.onerror = function(event) { console. log("Uh oh"); }; ws.onopen = function(event) { // Here we know connection is established, // so enable the UI to start sending! }; ws.onclose = function(event) { // Here the connection is closing (e.g. user is leaving page), // so stop sending stuff. };
  • 39. Client API (Other) • Non-Browser APIs for C/C++, Java, .NET, Perl, PHP, Python, C#, and probably others WebSocket webSocketClient = new WebSocket("ws://127.0.0.1:911/websocket", "basic"); webSocketClient.OnClose += new EventHandler(webSocketClient_OnClose); webSocketClient.OnMessage += new EventHandler<MessageEventArgs>(webSocketClient_OnMessage); webSocketClient.Connect()); webSocketClient.Send(“HELLO THERE SERVER!”); webSocketClient.Close();
  • 40. Browser Support • Your users don’t care about WebSockets • Fallback support: jQuery, Vaadin, Atmosphere, Socket.IO, Play, etc
  • 44. WebSocket Gotchas • Using WebSockets in a thread-based system (e.g. the JVM) • Sending or receiving data before connection is established, re-establishing connections • UTF-8 Encoding • Extensions, security, masking make debugging more challenging
  • 45. WebSocket Issues • Ephemeral Port Exhaustion • Evolving interfaces • Misbehaving Proxies
  • 46. Acknowledgements http://cs.brown.edu/courses/cs168/f12/handouts/async.pdf (Execution Models) http://www.infosecisland.com/blogview/12681-The-WebSocket-Protocol-Past-Travails-To-Be-Avoided.html (problems) http://lucumr.pocoo.org/2012/9/24/websockets-101/ (more problems) http://wmarkito.wordpress.com/2012/07/20/cdi-events-synchronous-x-asynchronous/ (cdi examples) http://blog.arungupta.me/2010/05/totd-139-asynchronous-request-processing-using-servlets-3-0-and-java-ee-6/ (async servlets) http://vertx.io (vert.x example) https://cwiki.apache.org/TUSCANYWIKI/develop-websocket-binding-for-apache-tuscany.html (handshake image) http://caniuse.com/websockets (browser compat graph)
  • 47. Asynchronous Web Programming with HTML5 WebSockets and Java James Falkner Community Manager, Liferay, Inc. [email protected] @schtool