Let web sockets hit that f5 for you

51
Let WebSockets hit that for you Slides: http://goo.gl/YH6lDp (YH6…lowercase “L”…Dp) Demo: http://goo.gl/7ecjYY

Transcript of Let web sockets hit that f5 for you

Page 1: Let web sockets hit that f5 for you

Let WebSockets hit that

for you

Slides:http://goo.gl/YH6lDp(YH6…lowercase “L”…Dp)

Demo:http://goo.gl/7ecjYY

Page 2: Let web sockets hit that f5 for you

About me

● Born and raised in MD● Developer at Teaching Strategies, LLC

○ Early childhood education resources● Past: UMD, UMUC, NASA, MD Archives, NIST● First time presenting at conference● Project: CFScript Converter

Page 3: Let web sockets hit that f5 for you

● HTML5 WebSockets● Pusher● CFWebSocket tag

Topics for today

Page 4: Let web sockets hit that f5 for you

Poll

Want real-time features now?

Have already implemented real-time features?

Page 5: Let web sockets hit that f5 for you

WebSockets

Page 6: Let web sockets hit that f5 for you

Real-time Web

Page 7: Let web sockets hit that f5 for you

Real-time Web“Realtime refers to the timely nature between an event’s occurrence and our being made aware of it.”

-Jason Lengstdorf and Phil Leggeter

Page 8: Let web sockets hit that f5 for you

Real-time

Page 9: Let web sockets hit that f5 for you

Real-time

Page 10: Let web sockets hit that f5 for you

Real-time

Page 11: Let web sockets hit that f5 for you
Page 12: Let web sockets hit that f5 for you

Use cases● System-wide alerts● CRUD forms● Live grids● Real-time graphs● Real-time maps● Business collaboration● Idle time sign off● CMS updates

Page 13: Let web sockets hit that f5 for you

Demos

Page 14: Let web sockets hit that f5 for you

Before WebSockets

● Java applets● ActiveX● Flash● Ajax

Page 15: Let web sockets hit that f5 for you

Polling

Page 16: Let web sockets hit that f5 for you

Long polling

Page 17: Let web sockets hit that f5 for you

2-year old’s approach

Dad are we there yet?

Dad are we there yet?

Dad are we there yet?

No

No

Yes!

Page 18: Let web sockets hit that f5 for you

HTTP headers are inefficientRequest URL:http://help.adobe.com/en_US/ColdFusion/10.0/Developing/terms.jsRequest Method:GETStatus Code:200 OKRequest Headersview source

Accept:*/*Accept-Encoding:gzip,deflate,sdchAccept-Language:en-US,en;q=0.8Cache-Control:max-age=0Connection:keep-aliveCookie:topicId=WSe61e35da8d31851852cc9f7d1353e88b409-7fff.html;kal3ljKFQLEkldekaaeka;kLEKELKFLiadaoeldoapkekEpakd

Page 19: Let web sockets hit that f5 for you

Streaming

● Is in fact a duplex connection● HTTP headers still included

Page 20: Let web sockets hit that f5 for you

● Full duplex connection○ Client and server maintain an open connection

● Light on bandwidth● Ability to broadcast messages● A brand new protocol

What we want

Page 21: Let web sockets hit that f5 for you

WebSockets URIs

ws://echo.websocket.org

wss://echo.websocket.org

Page 22: Let web sockets hit that f5 for you

WebSocket request

GET /echo HTTP/1.1 Host: echo.websocket.org Origin: http://www.websocket.org Sec-WebSocket-Key: 7+C600xYybOv2zmJ69RQsw== Sec-WebSocket-Version: 13 Upgrade: websocket

Page 23: Let web sockets hit that f5 for you

WebSockets response

101 Switching Protocols Connection: Upgrade Date: Wed, 20 Jun 2012 03:39:49 GMT Sec-WebSocket-Accept: fYoqiH14DgI+5ylEMwM2sOLzOi0= Server: Kaazing Gateway Upgrade: WebSocket

Page 24: Let web sockets hit that f5 for you

WebSockets eventsonopen : connection opened

onmessage : message received from server

onclose : connection closed (normally or abruptly)

onerror : error

Page 25: Let web sockets hit that f5 for you

HTML5 WebSockets API

Page 26: Let web sockets hit that f5 for you

Server-side Solutions

Page 27: Let web sockets hit that f5 for you

Server-side Libraries

Python● Tornado● Pywebsocket● Autobahn● txWS● WebSocket for Python

Ruby● Php-websocket● Rachet● Hoar

JavaScript● Socket IO● WebSocket-Node

.NET● IIS8● Fleck

PHP● Php-websocket● Rachet● Hoar

Java● Tomcat● JBoss● GlassFish● Jetty

Page 28: Let web sockets hit that f5 for you

Solutions

Pusher

ColdFusion 10+ CFWebSocket

Page 29: Let web sockets hit that f5 for you

PusherWeb page

Pusher.cfc

Pusher API

Client 1 Client 3Client 2 Client 4

(form post)

(Many thanks to Ben Nadel)

Page 30: Let web sockets hit that f5 for you

Channels

Pusher

Client 1 Client 3Client 2 Client 4 Client 5

Carousel Channel Emergency Alerts Channel DB Updates Channel

Page 31: Let web sockets hit that f5 for you

Unlimited Channels

Pusher

Channel 1 Channel (n)Channel 2 Channel 3 Channel 4 …

Page 32: Let web sockets hit that f5 for you

Unlimited Event Types

Channel

Event 1 Event (n)Event 2 Event 3 Event 4 …

Page 33: Let web sockets hit that f5 for you
Page 34: Let web sockets hit that f5 for you

Pusher.cfc

Page 35: Let web sockets hit that f5 for you
Page 36: Let web sockets hit that f5 for you

Code Walkthrough

Page 37: Let web sockets hit that f5 for you

Disadvantages

1. It costs $$$ based on traffic (e.g. 500 connections per month = $50)

2. Information goes through an external service (privacy)

Pusher

Advantages

1. Highly scalable2. Add new channels at any

time3. Custom events4. Will work on any platform,

even static HTML files5. One less thing to worry

about

Page 38: Let web sockets hit that f5 for you

CFWebSocketApplication.cfc

Page 39: Let web sockets hit that f5 for you

CFWebSocket

Page 40: Let web sockets hit that f5 for you

CFWebSocket

Page 41: Let web sockets hit that f5 for you

CFWebSocket

Page 42: Let web sockets hit that f5 for you

Disadvantages

1. Need to upgrade to CF10+

2. Can’t add channels dynamically (see Application.cfc)

3. Global JavaScript vars

4. Load balanced environment?

CFWebSocket

Advantages

1. Supports channel paradigm

2. Can integrate with internal authentication

3. Integrates with existing CFLogin/Authentication

Page 43: Let web sockets hit that f5 for you

Security

Page 44: Let web sockets hit that f5 for you

Security● Denial of service● Cross-site scripting (XSS)● Man in the Middle● Authentication

Client Server

Always use wss://

on production systems!!!

Page 45: Let web sockets hit that f5 for you

DDOS

Page 46: Let web sockets hit that f5 for you

XSS

Page 47: Let web sockets hit that f5 for you
Page 48: Let web sockets hit that f5 for you
Page 49: Let web sockets hit that f5 for you

Fallbacks

● Flash● Ajax Polling● Graceful WebSocket (jQuery plug-in)● Portal● DataChannel● Atmosphere● web-socket-js● Kaazing WebSocket Gateway

Page 50: Let web sockets hit that f5 for you

Realtime Web Apps (Apress)

The Definitive Guide to HTML5 WebSocket (Apress)

Getting Started with HTML5 WebSocket Programming (PacktPub)

*Echo test service

How can I get started?

Page 51: Let web sockets hit that f5 for you

The End

Contact MeTwitter: @joseGaldamezGitHub: http://github.com/galdamezE-mail: [email protected]