Slide 1

Slide 1 text

WEBSOCKETS

Slide 2

Slide 2 text

• phpBB • Symfony2 • Silex • Composer igorw @igorwesome

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

WEBSOCKETS

Slide 5

Slide 5 text

WEB

Slide 6

Slide 6 text

Application HTTP Presentation TCP Session TCP Transport TCP Network IP Data Link Physical

Slide 7

Slide 7 text

Application HTTP Presentation TCP Session TCP Transport TCP Network IP Data Link Physical

Slide 8

Slide 8 text

HTTP

Slide 9

Slide 9 text

client

Slide 10

Slide 10 text

request client

Slide 11

Slide 11 text

reponse client request

Slide 12

Slide 12 text

GET / HTTP/1.1 Host: igor.io >

Slide 13

Slide 13 text

HTTP/1.1 200 OK Server: nginx Content-Type: text/html; charset=UTF-8 Transfer-Encoding: chunked Connection: keep-alive cache-control: no-cache date: Mon, 14 May 2012 10:08:23 GMT Hello World! GET / HTTP/1.1 Host: igor.io > <

Slide 14

Slide 14 text

THIS IS A GOOD THING

Slide 15

Slide 15 text

BUT

Slide 16

Slide 16 text

NOT FOR EVERYTHING

Slide 17

Slide 17 text

UNIDIRECTIONAL

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

LATENCY

Slide 20

Slide 20 text

LATENCY KEEP-ALIVE PIPELINING SPDY

Slide 21

Slide 21 text

STATELESS

Slide 22

Slide 22 text

Application HTTP Presentation TCP Session TCP Transport TCP Network IP Data Link Physical

Slide 23

Slide 23 text

Application HTTP Presentation TCP Session TCP Transport TCP Network IP Data Link Physical

Slide 24

Slide 24 text

WEBSOCKETS

Slide 25

Slide 25 text

SOCKETS

Slide 26

Slide 26 text

WEBSOCKETS

Slide 27

Slide 27 text

PROTOCOL API

Slide 28

Slide 28 text

THE WEBSOCKET PROTOCOL

Slide 29

Slide 29 text

browser

Slide 30

Slide 30 text

No content

Slide 31

Slide 31 text

GET /foo HTTP/1.1 Host: localhost Connection: Upgrade Upgrade: websocket Sec-WebSocket-Key: ZQqy3/N7NzBwMak/2+aFIQ== Sec-WebSocket-Origin: ws://localhost:8080/foo Sec-WebSocket-Version: 13 >

Slide 32

Slide 32 text

GET /foo HTTP/1.1 Host: localhost Connection: Upgrade Upgrade: websocket Sec-WebSocket-Key: ZQqy3/N7NzBwMak/2+aFIQ== Sec-WebSocket-Origin: ws://localhost:8080/foo Sec-WebSocket-Version: 13 HTTP/1.1 101 Switching Protocols Upgrade: websocket Connection: Upgrade Sec-WebSocket-Accept: p5XeX6xlMI7WflwlN4B8OFqdWPA= > <

Slide 33

Slide 33 text

• Handshake / Upgrade • TCP + framing • Proxies • Supports TLS (SSL)

Slide 34

Slide 34 text

No content

Slide 35

Slide 35 text

RFC 6455

Slide 36

Slide 36 text

COMET

Slide 37

Slide 37 text

THE WEBSOCKET API

Slide 38

Slide 38 text

browser

Slide 39

Slide 39 text

No content

Slide 40

Slide 40 text

var ws = new WebSocket('ws://example.org:8080/updates'); ws.onopen = function () { ws.send('hello'); }; ws.onmessage = function (event) { console.log(event.data); };

Slide 41

Slide 41 text

JS INTERFACE • WebSocket • onopen • onmessage • onerror • onclose • binaryType • MessageEvent • data

Slide 42

Slide 42 text

browser API PROTOCOL

Slide 43

Slide 43 text

USE CASES •Games •Notifications •Collaboration •Statistics •Chat

Slide 44

Slide 44 text

4.0+ (2009) 6.0+ (2011) 10.70+ (2012) 5.0+ (2010) 10+ (2012)

Slide 45

Slide 45 text

• transport abstraction (fallbacks) • broadcasting, reconnection, serialization, other stuff • monolithic! (and almost trying to fix it)

Slide 46

Slide 46 text

SOCKJS

Slide 47

Slide 47 text

TRANSPORTS • Native WebSocket • Streaming • Polling

Slide 48

Slide 48 text

TRANSPORTS • Native WebSocket (RFC6455, hixie-76, hybi-10) • Streaming (xhr-streaming, xdr-streaming, iframe-eventsource, iframe-htmlfile) • Polling (xhr-polling, xdr-polling, iframe-xhr-polling, jsonp- polling)

Slide 49

Slide 49 text

No content

Slide 50

Slide 50 text

ASYNC STACK Connect (fix it, sencha) Express SockJS

Slide 51

Slide 51 text

ASYNC STACK ? ? SockJS

Slide 52

Slide 52 text

ASYNC STACK EventMachine ? ? SockJS

Slide 53

Slide 53 text

ASYNC STACK ? ? SockJS

Slide 54

Slide 54 text

Y U NO PHP?

Slide 55

Slide 55 text

SYNC STACK Application

Slide 56

Slide 56 text

SYNC STACK Application

Slide 57

Slide 57 text

ASYNC Connect (fix it, sencha) Express SockJS SYNC Application

Slide 58

Slide 58 text

No content

Slide 59

Slide 59 text

No content

Slide 60

Slide 60 text

*MQ

Slide 61

Slide 61 text

*MQ Sync Async

Slide 62

Slide 62 text

DEMO

Slide 63

Slide 63 text

•Pub/Sub •RPC MESSAGING PATTERNS

Slide 64

Slide 64 text

No content

Slide 65

Slide 65 text

No content

Slide 66

Slide 66 text

NULLMQ

Slide 67

Slide 67 text

DEBUGGING •printf •chrome inspector •wssh •ngrep •zmqc

Slide 68

Slide 68 text

RECAP • Use SockJS • Polyglot is the future • Learn from the MQs

Slide 69

Slide 69 text

LINKS • tools.ietf.org/html/rfc6455 • dev.w3.org/html5/websockets • developer.mozilla.org/en/WebSockets (fix it) • sockjs.org • github.com/igorw/websockets-talk

Slide 70

Slide 70 text

github.com/igorw/websockets-talk

Slide 71

Slide 71 text

CREDITS • thenounproject.com • stopwatch

Slide 72

Slide 72 text

Questions? @igorwesome speakerdeck.com /u/igorw joind.in/6421