+ All Categories
Home > Technology > Web Sockets in Java EE 7

Web Sockets in Java EE 7

Date post: 24-Dec-2014
Category:
Upload: sivasubramaniam-arunachalam
View: 5,743 times
Download: 14 times
Share this document with a friend
Description:
 
53
Web Sockets in Java EE 7 Sivasubramaniam Arunachalam February 23, 2013 @sivaa_in http://www.meetup.com/BangaloreOpenJUG/events/102904102/ Java Day
Transcript
Page 1: Web Sockets in Java EE 7

Web Sockets in Java EE 7

Sivasubramaniam Arunachalam

February 23, 2013

@sivaa_in

http://www.meetup.com/BangaloreOpenJUG/events/102904102/

Java Day

Page 2: Web Sockets in Java EE 7

It’s me!

• Application Developer

• Web/Enterprise/Middleware/B2B

• Java/Java EE, Python/Django

• 2002

• Technical Consultant

• Process Mentor • Speaker

Page 3: Web Sockets in Java EE 7

Agenda

• Introduction to Web Sockets

• History

• Protocol Spec

• Adoption

• Java EE 7 Support

• Demo

Page 4: Web Sockets in Java EE 7

Tweet Ping

Page 5: Web Sockets in Java EE 7

Web 1.0 Web 1.0

Web 2.0

Web 3.0 Web 4.0

Page 6: Web Sockets in Java EE 7

https://www.facebook.com/sitetour/chat.php

600+ M Active Users/Day

Page 7: Web Sockets in Java EE 7

http:// 1991

1995

2013 Still 22 Years Old

http?

Page 8: Web Sockets in Java EE 7

http/tcp (1974) (1991)

request / response

~ 2k bytes

~ 150 ms

State less

Page 9: Web Sockets in Java EE 7

Real Time Real Time ~

Page 10: Web Sockets in Java EE 7

Pull Based (Polling) Periodic Polling (JS/AJAX)

Server Client

AUS 312/7

Latest Score?

Latest Score?

Latest Score?

Same

Same

Latest Score?

AUS 316/7

Latest Score?

Same

Page 11: Web Sockets in Java EE 7

Push Based (Comet) Server Push/Long Polling (JS/AJAX/iframe)

Server Client

AUS 312/7

Latest Score?

Latest Score?

AUS 316/7

Latest Score?

Page 12: Web Sockets in Java EE 7

• Request / Response

• Too Many

• Server Connections

• Heavy Headers

• Outdated Content

Page 13: Web Sockets in Java EE 7

Streaming Server Side Hack

Server Client

AUS 312/7 (1/n)

Latest Score?

AUS 316/7 (2/n)

IND 0/0 (n/n)

Page 14: Web Sockets in Java EE 7

Server Client

AUS 312/7

Latest Score?

AUS 312/7 AUS 316/7 IND 0/0

Server Buffer

AUS 316/7

IND 0/0

PROXY

(1/n) (n-1 to go)

(n/n)

(2/n)

(n-2 to go)

Page 15: Web Sockets in Java EE 7

• RTMP • Adobe

• Are you Still using Flash?

• RTD • Windows/Excel

• Non Web

Others

Page 16: Web Sockets in Java EE 7

Web Sockets (to rescue)

Page 17: Web Sockets in Java EE 7

The Web Socket Way The Original Route

Server Client

Hi Client!

Hey Server!

AUS 312/7

Update me the Score

AUS 316/7

IND 0/0

Not Interested. Bye

Page 18: Web Sockets in Java EE 7

Server Client

Hi Client!

Hey Server!

AUS 312/7

Update me the Score

AUS 316/7

IND 0/0

Not Interested. Bye

Update Over info too

(0.0 ov)

(95.0 ov)

(93.0 ov)

(94.0 ov)

Page 19: Web Sockets in Java EE 7

The Background

Page 20: Web Sockets in Java EE 7

http://www.tavendo.de/webmq/resources/faq

Let’s Meet Next Year (2014)

Page 21: Web Sockets in Java EE 7

http://www.tavendo.de/webmq/resources/faq

Server Side • Hand Shake

• Data Transfer

RFC 6455

Client Side • Java Script API

• Browser Behavior

Page 22: Web Sockets in Java EE 7

• tcp • Full Duplex (Bi-Directional)

• Native Browser Support

• No Hacks

• Not Limited to Web

Fundamentals

+ http

Page 23: Web Sockets in Java EE 7

• 80 / 443 (plain/secure)

• No Proxy/Firewall pains

• Stream of Messages (Not Bytes)

• ws:// & wss://

• Only ONE Connection (up/down streams)

The Spec

Page 24: Web Sockets in Java EE 7

2 Bytes Header (for each message)

Still Why?

~ 50 ms (Latency)

1000 x

3 x

Page 25: Web Sockets in Java EE 7

http://www.codeproject.com/Articles/437342/DotNet-WebSocket-Programming

1 Message/Second per Client

1,000 clients 10,000 clients 1,00,000 clients

Page 26: Web Sockets in Java EE 7

• GET (request)

• 101 (response code)

• Not 200 OK

• http:// -> ws://

The Upgrade

Page 27: Web Sockets in Java EE 7

GET /demo HTTP/1.1

Origin : http://sivaa.in

Host : sivaa.in

Connection : Upgrade

Upgrade : WebSocket

WebSocket-Protocol : json, chat, <protocol>

WebSocket-Version : 10

WebSocket-extensions : compression, <extn>

Client Request

Page 28: Web Sockets in Java EE 7

HTTP/1.1 101 Switching Protocols

Connection : Upgrade

Upgrade : WebSocket

WebSocket-Protocol : json, chat, <protocol>

WebSocket-Origin : http://sivaa.in

WebSocket-Location : ws://sivaa.in/demo

Server Response

Page 29: Web Sockets in Java EE 7

Challenge by Client

Sec-WebSocket-Key : Key (Random 128 bits -> Base 64)

Response By Server

Sec-WebSocket-Accept : Key + GUID* (SHA1)

[NOT FOR SECURITY]

* 258EAFA5-E914-47DA- 95CA-C5AB0DC85B11 (RFC 6455)

Challenge - Response

Page 30: Web Sockets in Java EE 7

Client / Server Client / Server

Peer <-> Peer

Page 31: Web Sockets in Java EE 7

• Frames (TCP) •

• No request / response behavior • No Correlation too

• Independent

• # of requests != # of responses

Data Transfer

Page 32: Web Sockets in Java EE 7

• Headers

• Cookies

• Authentication

And No

Page 33: Web Sockets in Java EE 7

• Custom Message Patterns

• Technical / Business

• Request / Response • 1 – 1

• 1 to Many

• Acknowledgements

Sub Protocols

Page 34: Web Sockets in Java EE 7

Client -> Ping

Server -> Pong

Ping / Pong

• Keep-Alive

• Heart Beat

• Latency Metrics

• N/W Status Probing

• Detect Failed Connections

Page 35: Web Sockets in Java EE 7

Browser Support

http://caniuse.com/#feat=websockets

Page 36: Web Sockets in Java EE 7

Server Support

IDL (Java Script)

http://www.w3.org/TR/websockets/

Page 37: Web Sockets in Java EE 7

http://www.w3.org/TR/websockets/

Page 38: Web Sockets in Java EE 7

http://www.w3.org/TR/websockets/

Page 39: Web Sockets in Java EE 7

http://www.w3.org/TR/websockets/

Page 40: Web Sockets in Java EE 7

http://www.w3.org/TR/websockets/

Page 41: Web Sockets in Java EE 7

1. var ws = new WebSocket("ws://sivaa.in/demo");

2. ws.onopen = function() {

ws.send("Hello Server!");

};

3. ws.onmessage = function(event) {

alert("Reply from Server " + event.data);

};

n-1. ws.send("This is the message sent by the client");

n. ws.close()

Developer Friendly

CONNECTING

OPEN

CLOSING

CLOSED

Page 42: Web Sockets in Java EE 7

• Closing Long Lived Connections

• Unresponsive Server

• Buffering Server Response

• Non Encryption

• More Latency

The Guards (Proxy / Firewall)

Page 43: Web Sockets in Java EE 7

• Web Sockets doesn’t Proxy

• Stripping HTTP Headers • Upgrade

• Options to disable

• Rejecting Server Response

• Frames (HTTP Headers Expected)

• wss:// - No issues

Web Sockets and

The Guards

Page 44: Web Sockets in Java EE 7

• 301

• Limited Support

• Inconsistent Behavior

The Hidden Blades

Page 45: Web Sockets in Java EE 7

• JSR 356

• Java EE 7

• Tyrus ( http://tyrus.java.net/ )

• Web Socket SDK

• Reference Implementation

Java EE 7 & Web Socket

Page 46: Web Sockets in Java EE 7

• Handshake Response to Clients

• Source/Origin Check

• URI Resolving & Matching

• Sub Protocols Negotiation

• Extension Negotiation

Server Side Capabilities (Expected)

Page 47: Web Sockets in Java EE 7

• End point (to handle life cycle events)

• Session (Current Active Session)

• Remote End Point (Peer)

• Message Handler (incoming messages)

• Error Handler

Handlers

Page 48: Web Sockets in Java EE 7

• javax.websocket.*

• javax.net.websocket.*

http://java.net/projects/websocket-spec/sources/source-code-repository/show/tags/javax.net.websocket-api-1.0-b08/src/main/java?rev=213

Packages

Page 49: Web Sockets in Java EE 7

• Apache Tomcat 7

• GlassFish 3.1

• Jetty 7

• JBoss 7 • And much more

Web Server Support

Page 50: Web Sockets in Java EE 7

• Annotations

• Reference Implementation

• Web Sockets SDK / mvn

• Samples to Begin with

GlassFish

Page 52: Web Sockets in Java EE 7

Thank You! [email protected]

bit.ly/sivasubramaniam bit.ly/sivaa_in

Page 53: Web Sockets in Java EE 7

References

• http://www.inc.com/ss/brief-history-time-management#7 • http://resources3.news.com.au/images/2013/01/30/1226564/845955-tim-berners-lee.jpg • http://netdna.webdesignerdepot.com/uploads/2009/01/macii.jpg#old%20apple%20computer%20559x450 • http://3.bp.blogspot.com/_zVkfb2MIt4A/S8f_qzhuhRI/AAAAAAAAAjg/2idf7_G4wxo/s1600/apple-imac.png • http://www.softwareforeducation.com/wikileki/images/c/c4/Simplex-half-full.gif • http://www.mediafly.com/wp-content/uploads/Speed_Rocket-2.png • http://weaponsman.com/wp-content/uploads/2013/01/thumbs-down.png • http://m.flikie.com/ImageData/WallPapers/d1bef9f8be6d479387953929c766699a.jpg • http://www.tavendo.de/webmq/resources/faq • http://deadliestwebattacks.com/tag/websocket/ • http://en.wikipedia.org/wiki/WebSocket • http://www.infoq.com/articles/Web-Sockets-Proxy-Servers


Recommended