SlideShare uma empresa Scribd logo
1 de 39
Baixar para ler offline
{CJUG}

WebSockets in Java
Jonathan Freeman
@freethejazz
{Open Software Integrators} { www.osintegrators.com} {@osintegrators}
WebSockets in Java

Open Software Integrators
●

Jonathan Freeman
@freethejazz

Founded January 2008 by Andrew C. Oliver
○ Durham, NC

Revenue and staff has at least doubled every year since
2009.
●

New office (2012) in Chicago, IL
○ We're hiring associate to senior level as well as UI Developers
(JQuery, Javascript, HTML, CSS)
○ Up to 50% travel (probably less), salary + bonus, 401k, health,
etc etc
○ Preferred: Java, Tomcat, JBoss, Hibernate, Spring, RDBMS,
JQuery
○ Nice to have: Hadoop, Neo4j, MongoDB, Ruby a/o at least one
Cloud platform

{Open Software Integrators} { www.osintegrators.com} {@osintegrators}
WebSockets in Java

Overview

Jonathan Freeman
@freethejazz

● Gradients of client server communication
● Intro to WebSockets
● Implementing WebSockets

{Open Software Integrators} { www.osintegrators.com} {@osintegrators}
{WebSockets in Java}

Client/Server
Communication

{Open Software Integrators} { www.osintegrators.com} {@osintegrators}
WebSockets in Java
Jonathan Freeman
@freethejazz

Basic Web Applications

{Open Software Integrators} { www.osintegrators.com} {@osintegrators}
WebSockets in Java
Jonathan Freeman
@freethejazz

{Open Software Integrators} { www.osintegrators.com} {@osintegrators}
WebSockets in Java
Jonathan Freeman
@freethejazz

Pros
●
●
●

Simple
Client gets what it wants(and when)
Minimal interaction between the server and the client

For the server, this is a highly reactive model. Sits around waiting until it gets a request, then
delivers back whatever is needed.

Cons
●
●

Server cannot initiate the communication, only the client
new client request == new page load

{Open Software Integrators} { www.osintegrators.com} {@osintegrators}
WebSockets in Java
Jonathan Freeman
@freethejazz

How do we add more interaction
between the client and the server?

{Open Software Integrators} { www.osintegrators.com} {@osintegrators}
WebSockets in Java
Jonathan Freeman
@freethejazz

Variations on the basic model
● AJAX
● Long-Polling
New models
● SSE
● WebSockets

{Open Software Integrators} { www.osintegrators.com} {@osintegrators}
WebSockets in Java
Jonathan Freeman
@freethejazz

AJAX

{Open Software Integrators} { www.osintegrators.com} {@osintegrators}
WebSockets in Java
Jonathan Freeman
@freethejazz

{Open Software Integrators} { www.osintegrators.com} {@osintegrators}
WebSockets in Java
Jonathan Freeman
@freethejazz

Pros
●
●
●
●
●

Simple
Client gets what it wants(and when)
Minimal interaction between the server and the client
Piecemeal approach adds value to the client
Client can update based on the response from the server without loading a new page.

For the server, this is a still highly reactive model. Sits around waiting until it gets a request, then
delivers back whatever is needed.

Cons
●
●

Server cannot initiate the communication
New client request != new page load

{Open Software Integrators} { www.osintegrators.com} {@osintegrators}
WebSockets in Java
Jonathan Freeman
@freethejazz

Long Polling

{Open Software Integrators} { www.osintegrators.com} {@osintegrators}
WebSockets in Java
Jonathan Freeman
@freethejazz

{Open Software Integrators} { www.osintegrators.com} {@osintegrators}
WebSockets in Java
Jonathan Freeman
@freethejazz

Pros
●

Emulating a more real-time communication model from server to client.

Cons
●
●

Dealing with more longer and repeated connections, so you’ll have to account for that
It’s kind of a hack.

{Open Software Integrators} { www.osintegrators.com} {@osintegrators}
WebSockets in Java
Jonathan Freeman
@freethejazz

Server-Sent Events

{Open Software Integrators} { www.osintegrators.com} {@osintegrators}
WebSockets in Java
Jonathan Freeman
@freethejazz

{Open Software Integrators} { www.osintegrators.com} {@osintegrators}
WebSockets in Java
Jonathan Freeman
@freethejazz

Pros
●

A real-time communication model from server to client

Cons
●

Communication is only one way

{Open Software Integrators} { www.osintegrators.com} {@osintegrators}
{WebSockets in Java}

Intro to
WebSockets

{Open Software Integrators} { www.osintegrators.com} {@osintegrators}
WebSockets in Java
Jonathan Freeman
@freethejazz

{Open Software Integrators} { www.osintegrators.com} {@osintegrators}
WebSockets in Java
Jonathan Freeman
@freethejazz

Pros
●

A real-time communication model

Cons
●
●
●

May be overkill for your particular application
Spec still being defined
Security vulnerabilities in previous implementation

{Open Software Integrators} { www.osintegrators.com} {@osintegrators}
WebSockets in Java
Jonathan Freeman
@freethejazz

Why use WebSockets?

{Open Software Integrators} { www.osintegrators.com} {@osintegrators}
WebSockets in Java
Jonathan Freeman
@freethejazz

●
●
●
●

Chat applications
Instagram-like applications(social streams)
Financial tickers
Multiplayer games

{Open Software Integrators} { www.osintegrators.com} {@osintegrators}
{WebSockets in Java}

Implementing
WebSockets

{Open Software Integrators} { www.osintegrators.com} {@osintegrators}
WebSockets in Java
Jonathan Freeman
@freethejazz

1. Create an endpoint class
(programmatic or annotated)
2. Override/annotate the lifecycle methods
(depending on how you create the endpoint)
3. Add your business logic
4. Deploy!

{Open Software Integrators} { www.osintegrators.com} {@osintegrators}
WebSockets in Java
Jonathan Freeman
@freethejazz
Creating the endpoint class
public class MyWebSocketEndoint extends Endpoint {
@Override
public void onOpen(final Session session, EndpointConfig config) {
session.addMessageHandler(new MessageHandler.Whole<String>() {
@Override
public void onMessage(String msg) {
try {
session.getBasicRemote().sendText(msg);
} catch (IOException e) { ... }
}
});
}
}
{Open Software Integrators} { www.osintegrators.com} {@osintegrators}
WebSockets in Java
Jonathan Freeman
@freethejazz

MessageHandler methods to override:
onMessage

{Open Software Integrators} { www.osintegrators.com} {@osintegrators}
WebSockets in Java
Jonathan Freeman
@freethejazz

ServerEndpointConfig.Builder.create(MySocketEndpoint.class,
"/mywebsocket").build();

{Open Software Integrators} { www.osintegrators.com} {@osintegrators}
WebSockets in Java
Jonathan Freeman
@freethejazz
Creating the endpoint class
@ServerEndpoint("/mywebsocket")
public class MyWebSocketEndpoint {
@OnMessage
public void onMessage(Session session, String message) {
try {
//to do some work
} catch (IOException e) { ... }
}
}

{Open Software Integrators} { www.osintegrators.com} {@osintegrators}
WebSockets in Java
Jonathan Freeman
@freethejazz

Possible Annotations:
@OnOpen
@OnMessage
@OnError
@OnClose

{Open Software Integrators} { www.osintegrators.com} {@osintegrators}
WebSockets in Java
Jonathan Freeman
@freethejazz
Sending a response to a single client
@ServerEndpoint("/mywebsocket")
public class MyWebSocketEndpoint {
@OnMessage
public void onMessage(Session session, String message) {
RemoteEndpoint remote = session.getBasicRemote();
try {
remote.sendText(message);
} catch (IOException e) { ... }
}
}

{Open Software Integrators} { www.osintegrators.com} {@osintegrators}
WebSockets in Java
Jonathan Freeman
@freethejazz
Sending a response to all connected clients
@ServerEndpoint("/mywebsocket")
public class MyWebSocketEndpoint {
@OnMessage
public void onMessage(Session session, String message) {
try {
for (Session sess : session.getOpenSessions()) {
if (sess.isOpen())
sess.getBasicRemote().sendText(message);
}
} catch (IOException e) { ... }
}
}

{Open Software Integrators} { www.osintegrators.com} {@osintegrators}
WebSockets in Java
Jonathan Freeman
@freethejazz

In Spring 4...

{Open Software Integrators} { www.osintegrators.com} {@osintegrators}
WebSockets in Java
Jonathan Freeman
@freethejazz

@Controller
public class MyWebSocketController {
@RequestMapping(value=”/mywebsocket”, method=POST)
public void overHttp(String text) {
// ...
}
@MessageMapping("/mywebsocket")
public void overStomp(String text) {
// ...
}
}

http://blog.gopivotal.com/products/websocket-architecture-in-spring-4-0
http://assets.spring.io/wp/WebSocketBlogPost.html

{Open Software Integrators} { www.osintegrators.com} {@osintegrators}
WebSockets in Java
Jonathan Freeman
@freethejazz

References:
https://www.openshift.com/blogs/how-to-build-java-websocket-applications-using-the-jsr-356-api
http://docs.oracle.com/javaee/7/tutorial/doc/websocket.htm

{Open Software Integrators} { www.osintegrators.com} {@osintegrators}
WebSockets in Java
Jonathan Freeman
@freethejazz
Image Attribution:
client-server communication diagrams: http://stackoverflow.com/questions/11077857/what-are-longpolling-websockets-server-sent-events-sse-and-comet

{Open Software Integrators} { www.osintegrators.com} {@osintegrators}
{WebSockets in Java}

Thank You

{Open Software Integrators} { www.osintegrators.com} {@osintegrators}

Mais conteúdo relacionado

Mais procurados

Razor into the Razor'verse
Razor into the Razor'verseRazor into the Razor'verse
Razor into the Razor'verseEd Charbeneau
 
Overview of React.JS - Internship Presentation - Week 5
Overview of React.JS - Internship Presentation - Week 5Overview of React.JS - Internship Presentation - Week 5
Overview of React.JS - Internship Presentation - Week 5Devang Garach
 
HTML5 for PHP Developers - IPC
HTML5 for PHP Developers - IPCHTML5 for PHP Developers - IPC
HTML5 for PHP Developers - IPCMayflower GmbH
 
Goodbye JavaScript Hello Blazor
Goodbye JavaScript Hello BlazorGoodbye JavaScript Hello Blazor
Goodbye JavaScript Hello BlazorEd Charbeneau
 
Simple todo app with meteor
Simple todo app with meteorSimple todo app with meteor
Simple todo app with meteorAlex Long
 
HTML5: what's new?
HTML5: what's new?HTML5: what's new?
HTML5: what's new?Chris Mills
 
Polytechnic 1.0 Granada
Polytechnic 1.0 GranadaPolytechnic 1.0 Granada
Polytechnic 1.0 GranadaIsrael Blancas
 
Understanding progressive enhancement - yuiconf2010
Understanding progressive enhancement - yuiconf2010Understanding progressive enhancement - yuiconf2010
Understanding progressive enhancement - yuiconf2010Christian Heilmann
 
High Performance JavaScript (CapitolJS 2011)
High Performance JavaScript (CapitolJS 2011)High Performance JavaScript (CapitolJS 2011)
High Performance JavaScript (CapitolJS 2011)Nicholas Zakas
 
Pragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScriptPragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScriptdavejohnson
 
DODN2009 - Jump Start Silverlight
DODN2009 - Jump Start SilverlightDODN2009 - Jump Start Silverlight
DODN2009 - Jump Start SilverlightClint Edmonson
 
eCommerce performance, what is it costing you and what can you do about it?
eCommerce performance, what is it costing you and what can you do about it?eCommerce performance, what is it costing you and what can you do about it?
eCommerce performance, what is it costing you and what can you do about it?Peter Holditch
 
How to make Ajax work for you
How to make Ajax work for youHow to make Ajax work for you
How to make Ajax work for youSimon Willison
 
Ditching jQuery Madison
Ditching jQuery MadisonDitching jQuery Madison
Ditching jQuery MadisonHao Luo
 
Don't make me wait! or Building High-Performance Web Applications
Don't make me wait! or Building High-Performance Web ApplicationsDon't make me wait! or Building High-Performance Web Applications
Don't make me wait! or Building High-Performance Web ApplicationsStoyan Stefanov
 
Passo a Passo para criar uma aplicação Móvel Híbrida
Passo a Passo para criar uma aplicação Móvel HíbridaPasso a Passo para criar uma aplicação Móvel Híbrida
Passo a Passo para criar uma aplicação Móvel HíbridaJuliano Martins
 

Mais procurados (20)

What is HTML 5?
What is HTML 5?What is HTML 5?
What is HTML 5?
 
Razor into the Razor'verse
Razor into the Razor'verseRazor into the Razor'verse
Razor into the Razor'verse
 
Html web workers
Html web workersHtml web workers
Html web workers
 
Overview of React.JS - Internship Presentation - Week 5
Overview of React.JS - Internship Presentation - Week 5Overview of React.JS - Internship Presentation - Week 5
Overview of React.JS - Internship Presentation - Week 5
 
HTML5 for PHP Developers - IPC
HTML5 for PHP Developers - IPCHTML5 for PHP Developers - IPC
HTML5 for PHP Developers - IPC
 
Goodbye JavaScript Hello Blazor
Goodbye JavaScript Hello BlazorGoodbye JavaScript Hello Blazor
Goodbye JavaScript Hello Blazor
 
Simple todo app with meteor
Simple todo app with meteorSimple todo app with meteor
Simple todo app with meteor
 
HTML5: what's new?
HTML5: what's new?HTML5: what's new?
HTML5: what's new?
 
Polytechnic 1.0 Granada
Polytechnic 1.0 GranadaPolytechnic 1.0 Granada
Polytechnic 1.0 Granada
 
Understanding progressive enhancement - yuiconf2010
Understanding progressive enhancement - yuiconf2010Understanding progressive enhancement - yuiconf2010
Understanding progressive enhancement - yuiconf2010
 
High Performance JavaScript (CapitolJS 2011)
High Performance JavaScript (CapitolJS 2011)High Performance JavaScript (CapitolJS 2011)
High Performance JavaScript (CapitolJS 2011)
 
Pragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScriptPragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScript
 
Blazor Full-Stack
Blazor Full-StackBlazor Full-Stack
Blazor Full-Stack
 
DODN2009 - Jump Start Silverlight
DODN2009 - Jump Start SilverlightDODN2009 - Jump Start Silverlight
DODN2009 - Jump Start Silverlight
 
eCommerce performance, what is it costing you and what can you do about it?
eCommerce performance, what is it costing you and what can you do about it?eCommerce performance, what is it costing you and what can you do about it?
eCommerce performance, what is it costing you and what can you do about it?
 
How to make Ajax work for you
How to make Ajax work for youHow to make Ajax work for you
How to make Ajax work for you
 
Ditching jQuery Madison
Ditching jQuery MadisonDitching jQuery Madison
Ditching jQuery Madison
 
Grails and Dojo
Grails and DojoGrails and Dojo
Grails and Dojo
 
Don't make me wait! or Building High-Performance Web Applications
Don't make me wait! or Building High-Performance Web ApplicationsDon't make me wait! or Building High-Performance Web Applications
Don't make me wait! or Building High-Performance Web Applications
 
Passo a Passo para criar uma aplicação Móvel Híbrida
Passo a Passo para criar uma aplicação Móvel HíbridaPasso a Passo para criar uma aplicação Móvel Híbrida
Passo a Passo para criar uma aplicação Móvel Híbrida
 

Semelhante a Intro to WebSockets (in Java)

Beginning AngularJS
Beginning AngularJSBeginning AngularJS
Beginning AngularJSTroy Miles
 
An Introduction to Web Components
An Introduction to Web ComponentsAn Introduction to Web Components
An Introduction to Web ComponentsRed Pill Now
 
Intro to SpringBatch NoSQL 2021
Intro to SpringBatch NoSQL 2021Intro to SpringBatch NoSQL 2021
Intro to SpringBatch NoSQL 2021Slobodan Lohja
 
Client-Side Performance Testing
Client-Side Performance TestingClient-Side Performance Testing
Client-Side Performance TestingAnand Bagmar
 
JSFest 2019: Technology agnostic microservices at SPA frontend
JSFest 2019: Technology agnostic microservices at SPA frontendJSFest 2019: Technology agnostic microservices at SPA frontend
JSFest 2019: Technology agnostic microservices at SPA frontendVlad Fedosov
 
Architecting single-page front-end apps
Architecting single-page front-end appsArchitecting single-page front-end apps
Architecting single-page front-end appsZohar Arad
 
Using Ajax In Domino Web Applications
Using Ajax In Domino Web ApplicationsUsing Ajax In Domino Web Applications
Using Ajax In Domino Web Applicationsdominion
 
Ajax Testing Approach
Ajax Testing ApproachAjax Testing Approach
Ajax Testing ApproachHarshJ
 
Ajax Testing Approach
Ajax Testing ApproachAjax Testing Approach
Ajax Testing ApproachHarshaVJoshi
 
Reactive Application Using METEOR
Reactive Application Using METEORReactive Application Using METEOR
Reactive Application Using METEORNodeXperts
 
Understanding and Developing Web Services - For DBAs and Developers
Understanding and Developing Web Services - For DBAs and DevelopersUnderstanding and Developing Web Services - For DBAs and Developers
Understanding and Developing Web Services - For DBAs and DevelopersRevelation Technologies
 
Developing high performance and responsive web apps using web worker
Developing high performance and responsive web apps using web workerDeveloping high performance and responsive web apps using web worker
Developing high performance and responsive web apps using web workerSuresh Patidar
 
KiranGara_JEE_7Yrs
KiranGara_JEE_7YrsKiranGara_JEE_7Yrs
KiranGara_JEE_7YrsKiran Gara
 
Understanding and Developing Web Services: For DBAs and Database Developers
Understanding and Developing Web Services: For DBAs and Database DevelopersUnderstanding and Developing Web Services: For DBAs and Database Developers
Understanding and Developing Web Services: For DBAs and Database DevelopersRevelation Technologies
 
JS Fest 2019/Autumn. Влад Федосов. Technology agnostic microservices at SPA f...
JS Fest 2019/Autumn. Влад Федосов. Technology agnostic microservices at SPA f...JS Fest 2019/Autumn. Влад Федосов. Technology agnostic microservices at SPA f...
JS Fest 2019/Autumn. Влад Федосов. Technology agnostic microservices at SPA f...JSFestUA
 

Semelhante a Intro to WebSockets (in Java) (20)

Beginning AngularJS
Beginning AngularJSBeginning AngularJS
Beginning AngularJS
 
An Introduction to Web Components
An Introduction to Web ComponentsAn Introduction to Web Components
An Introduction to Web Components
 
Intro to SpringBatch NoSQL 2021
Intro to SpringBatch NoSQL 2021Intro to SpringBatch NoSQL 2021
Intro to SpringBatch NoSQL 2021
 
Client-Side Performance Testing
Client-Side Performance TestingClient-Side Performance Testing
Client-Side Performance Testing
 
JSFest 2019: Technology agnostic microservices at SPA frontend
JSFest 2019: Technology agnostic microservices at SPA frontendJSFest 2019: Technology agnostic microservices at SPA frontend
JSFest 2019: Technology agnostic microservices at SPA frontend
 
Architecting single-page front-end apps
Architecting single-page front-end appsArchitecting single-page front-end apps
Architecting single-page front-end apps
 
Using Ajax In Domino Web Applications
Using Ajax In Domino Web ApplicationsUsing Ajax In Domino Web Applications
Using Ajax In Domino Web Applications
 
Getting Started with J2EE, A Roadmap
Getting Started with J2EE, A RoadmapGetting Started with J2EE, A Roadmap
Getting Started with J2EE, A Roadmap
 
Ajax Testing Approach
Ajax Testing ApproachAjax Testing Approach
Ajax Testing Approach
 
Ajax Testing Approach
Ajax Testing ApproachAjax Testing Approach
Ajax Testing Approach
 
Reactive Application Using METEOR
Reactive Application Using METEORReactive Application Using METEOR
Reactive Application Using METEOR
 
Cqrs api v2
Cqrs api v2Cqrs api v2
Cqrs api v2
 
GDG Ibadan #pwa
GDG Ibadan #pwaGDG Ibadan #pwa
GDG Ibadan #pwa
 
Understanding and Developing Web Services - For DBAs and Developers
Understanding and Developing Web Services - For DBAs and DevelopersUnderstanding and Developing Web Services - For DBAs and Developers
Understanding and Developing Web Services - For DBAs and Developers
 
Node.js Tools Ecosystem
Node.js Tools EcosystemNode.js Tools Ecosystem
Node.js Tools Ecosystem
 
Developing high performance and responsive web apps using web worker
Developing high performance and responsive web apps using web workerDeveloping high performance and responsive web apps using web worker
Developing high performance and responsive web apps using web worker
 
KiranGara_JEE_7Yrs
KiranGara_JEE_7YrsKiranGara_JEE_7Yrs
KiranGara_JEE_7Yrs
 
Understanding and Developing Web Services: For DBAs and Database Developers
Understanding and Developing Web Services: For DBAs and Database DevelopersUnderstanding and Developing Web Services: For DBAs and Database Developers
Understanding and Developing Web Services: For DBAs and Database Developers
 
JS Fest 2019/Autumn. Влад Федосов. Technology agnostic microservices at SPA f...
JS Fest 2019/Autumn. Влад Федосов. Technology agnostic microservices at SPA f...JS Fest 2019/Autumn. Влад Федосов. Technology agnostic microservices at SPA f...
JS Fest 2019/Autumn. Влад Федосов. Technology agnostic microservices at SPA f...
 
Dust.js
Dust.jsDust.js
Dust.js
 

Último

Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 

Último (20)

Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 

Intro to WebSockets (in Java)

  • 1. {CJUG} WebSockets in Java Jonathan Freeman @freethejazz {Open Software Integrators} { www.osintegrators.com} {@osintegrators}
  • 2. WebSockets in Java Open Software Integrators ● Jonathan Freeman @freethejazz Founded January 2008 by Andrew C. Oliver ○ Durham, NC Revenue and staff has at least doubled every year since 2009. ● New office (2012) in Chicago, IL ○ We're hiring associate to senior level as well as UI Developers (JQuery, Javascript, HTML, CSS) ○ Up to 50% travel (probably less), salary + bonus, 401k, health, etc etc ○ Preferred: Java, Tomcat, JBoss, Hibernate, Spring, RDBMS, JQuery ○ Nice to have: Hadoop, Neo4j, MongoDB, Ruby a/o at least one Cloud platform {Open Software Integrators} { www.osintegrators.com} {@osintegrators}
  • 3. WebSockets in Java Overview Jonathan Freeman @freethejazz ● Gradients of client server communication ● Intro to WebSockets ● Implementing WebSockets {Open Software Integrators} { www.osintegrators.com} {@osintegrators}
  • 4. {WebSockets in Java} Client/Server Communication {Open Software Integrators} { www.osintegrators.com} {@osintegrators}
  • 5. WebSockets in Java Jonathan Freeman @freethejazz Basic Web Applications {Open Software Integrators} { www.osintegrators.com} {@osintegrators}
  • 6. WebSockets in Java Jonathan Freeman @freethejazz {Open Software Integrators} { www.osintegrators.com} {@osintegrators}
  • 7. WebSockets in Java Jonathan Freeman @freethejazz Pros ● ● ● Simple Client gets what it wants(and when) Minimal interaction between the server and the client For the server, this is a highly reactive model. Sits around waiting until it gets a request, then delivers back whatever is needed. Cons ● ● Server cannot initiate the communication, only the client new client request == new page load {Open Software Integrators} { www.osintegrators.com} {@osintegrators}
  • 8. WebSockets in Java Jonathan Freeman @freethejazz How do we add more interaction between the client and the server? {Open Software Integrators} { www.osintegrators.com} {@osintegrators}
  • 9. WebSockets in Java Jonathan Freeman @freethejazz Variations on the basic model ● AJAX ● Long-Polling New models ● SSE ● WebSockets {Open Software Integrators} { www.osintegrators.com} {@osintegrators}
  • 10. WebSockets in Java Jonathan Freeman @freethejazz AJAX {Open Software Integrators} { www.osintegrators.com} {@osintegrators}
  • 11. WebSockets in Java Jonathan Freeman @freethejazz {Open Software Integrators} { www.osintegrators.com} {@osintegrators}
  • 12. WebSockets in Java Jonathan Freeman @freethejazz Pros ● ● ● ● ● Simple Client gets what it wants(and when) Minimal interaction between the server and the client Piecemeal approach adds value to the client Client can update based on the response from the server without loading a new page. For the server, this is a still highly reactive model. Sits around waiting until it gets a request, then delivers back whatever is needed. Cons ● ● Server cannot initiate the communication New client request != new page load {Open Software Integrators} { www.osintegrators.com} {@osintegrators}
  • 13. WebSockets in Java Jonathan Freeman @freethejazz Long Polling {Open Software Integrators} { www.osintegrators.com} {@osintegrators}
  • 14. WebSockets in Java Jonathan Freeman @freethejazz {Open Software Integrators} { www.osintegrators.com} {@osintegrators}
  • 15. WebSockets in Java Jonathan Freeman @freethejazz Pros ● Emulating a more real-time communication model from server to client. Cons ● ● Dealing with more longer and repeated connections, so you’ll have to account for that It’s kind of a hack. {Open Software Integrators} { www.osintegrators.com} {@osintegrators}
  • 16. WebSockets in Java Jonathan Freeman @freethejazz Server-Sent Events {Open Software Integrators} { www.osintegrators.com} {@osintegrators}
  • 17. WebSockets in Java Jonathan Freeman @freethejazz {Open Software Integrators} { www.osintegrators.com} {@osintegrators}
  • 18. WebSockets in Java Jonathan Freeman @freethejazz Pros ● A real-time communication model from server to client Cons ● Communication is only one way {Open Software Integrators} { www.osintegrators.com} {@osintegrators}
  • 19.
  • 20. {WebSockets in Java} Intro to WebSockets {Open Software Integrators} { www.osintegrators.com} {@osintegrators}
  • 21. WebSockets in Java Jonathan Freeman @freethejazz {Open Software Integrators} { www.osintegrators.com} {@osintegrators}
  • 22. WebSockets in Java Jonathan Freeman @freethejazz Pros ● A real-time communication model Cons ● ● ● May be overkill for your particular application Spec still being defined Security vulnerabilities in previous implementation {Open Software Integrators} { www.osintegrators.com} {@osintegrators}
  • 23.
  • 24. WebSockets in Java Jonathan Freeman @freethejazz Why use WebSockets? {Open Software Integrators} { www.osintegrators.com} {@osintegrators}
  • 25. WebSockets in Java Jonathan Freeman @freethejazz ● ● ● ● Chat applications Instagram-like applications(social streams) Financial tickers Multiplayer games {Open Software Integrators} { www.osintegrators.com} {@osintegrators}
  • 26. {WebSockets in Java} Implementing WebSockets {Open Software Integrators} { www.osintegrators.com} {@osintegrators}
  • 27. WebSockets in Java Jonathan Freeman @freethejazz 1. Create an endpoint class (programmatic or annotated) 2. Override/annotate the lifecycle methods (depending on how you create the endpoint) 3. Add your business logic 4. Deploy! {Open Software Integrators} { www.osintegrators.com} {@osintegrators}
  • 28. WebSockets in Java Jonathan Freeman @freethejazz Creating the endpoint class public class MyWebSocketEndoint extends Endpoint { @Override public void onOpen(final Session session, EndpointConfig config) { session.addMessageHandler(new MessageHandler.Whole<String>() { @Override public void onMessage(String msg) { try { session.getBasicRemote().sendText(msg); } catch (IOException e) { ... } } }); } } {Open Software Integrators} { www.osintegrators.com} {@osintegrators}
  • 29. WebSockets in Java Jonathan Freeman @freethejazz MessageHandler methods to override: onMessage {Open Software Integrators} { www.osintegrators.com} {@osintegrators}
  • 30. WebSockets in Java Jonathan Freeman @freethejazz ServerEndpointConfig.Builder.create(MySocketEndpoint.class, "/mywebsocket").build(); {Open Software Integrators} { www.osintegrators.com} {@osintegrators}
  • 31. WebSockets in Java Jonathan Freeman @freethejazz Creating the endpoint class @ServerEndpoint("/mywebsocket") public class MyWebSocketEndpoint { @OnMessage public void onMessage(Session session, String message) { try { //to do some work } catch (IOException e) { ... } } } {Open Software Integrators} { www.osintegrators.com} {@osintegrators}
  • 32. WebSockets in Java Jonathan Freeman @freethejazz Possible Annotations: @OnOpen @OnMessage @OnError @OnClose {Open Software Integrators} { www.osintegrators.com} {@osintegrators}
  • 33. WebSockets in Java Jonathan Freeman @freethejazz Sending a response to a single client @ServerEndpoint("/mywebsocket") public class MyWebSocketEndpoint { @OnMessage public void onMessage(Session session, String message) { RemoteEndpoint remote = session.getBasicRemote(); try { remote.sendText(message); } catch (IOException e) { ... } } } {Open Software Integrators} { www.osintegrators.com} {@osintegrators}
  • 34. WebSockets in Java Jonathan Freeman @freethejazz Sending a response to all connected clients @ServerEndpoint("/mywebsocket") public class MyWebSocketEndpoint { @OnMessage public void onMessage(Session session, String message) { try { for (Session sess : session.getOpenSessions()) { if (sess.isOpen()) sess.getBasicRemote().sendText(message); } } catch (IOException e) { ... } } } {Open Software Integrators} { www.osintegrators.com} {@osintegrators}
  • 35. WebSockets in Java Jonathan Freeman @freethejazz In Spring 4... {Open Software Integrators} { www.osintegrators.com} {@osintegrators}
  • 36. WebSockets in Java Jonathan Freeman @freethejazz @Controller public class MyWebSocketController { @RequestMapping(value=”/mywebsocket”, method=POST) public void overHttp(String text) { // ... } @MessageMapping("/mywebsocket") public void overStomp(String text) { // ... } } http://blog.gopivotal.com/products/websocket-architecture-in-spring-4-0 http://assets.spring.io/wp/WebSocketBlogPost.html {Open Software Integrators} { www.osintegrators.com} {@osintegrators}
  • 37. WebSockets in Java Jonathan Freeman @freethejazz References: https://www.openshift.com/blogs/how-to-build-java-websocket-applications-using-the-jsr-356-api http://docs.oracle.com/javaee/7/tutorial/doc/websocket.htm {Open Software Integrators} { www.osintegrators.com} {@osintegrators}
  • 38. WebSockets in Java Jonathan Freeman @freethejazz Image Attribution: client-server communication diagrams: http://stackoverflow.com/questions/11077857/what-are-longpolling-websockets-server-sent-events-sse-and-comet {Open Software Integrators} { www.osintegrators.com} {@osintegrators}
  • 39. {WebSockets in Java} Thank You {Open Software Integrators} { www.osintegrators.com} {@osintegrators}