The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to...

105
The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon. November 2012.

Transcript of The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to...

Page 1: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

The realtime web: HTTP/1.1 to WebSocket, SPDY and beyondGuillermo Rauch @ QCon. November 2012.

Page 2: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

Guillermo.

Page 3: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

CTO and co-founder at LearnBoost.

Page 4: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

Creator of socket.io and engine.io.

Page 5: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

@rauchg on twitter

Page 6: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

http://devthought.com

Page 7: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

Author of Wiley’s Smashing Nodehttp://smashingnode.com

Page 8: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

The realtime web

Page 9: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

HTTP over TCP/IP

Page 10: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

No specific techniques or protocols

Page 11: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

Realtime = fast data exchange.

Page 12: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

Let's analyze the timeline of a typical web request.

Page 13: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

https://mywebsite.com

Page 14: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

1. We first need to look up the DNS record for mywebsite.com

Page 15: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

DNS. Low bandwidth. Potentially high latency.

Page 16: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

Browsers have different approaches and optimizations.

Page 17: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

Our best shot at optimizing this is <link rel="dns-prefetch">.

Page 18: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

2. http vs https.

Page 19: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

“In January this year (2010), Gmail switched to using HTTPS for everything by default […] In our production frontend machines, SSL/TLS accounts for less than 1% of the CPU load, less than 10KB of memory per connection and less than 2% of network overhead.”http://www.imperialviolet.org/2010/06/25/overclocking-ssl.html (emphasis mine)

Page 20: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

SSL allows us to upgrade the protocol without breaking outdated proxies (eg: WebSocket).

Page 21: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

3. Request headers1. Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.82. Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.33. Accept-Encoding:gzip,deflate,sdch4. Accept-Language:en-US,en;q=0.85. Cache-Control:max-age=06. Connection:keep-alive7. Host:www.imperialviolet.org8. If-Modified-Since:Tue, 06 Nov 2012 21:22:53 GMT9. User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.5 Safari/537.17

Page 22: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

Consider a character-by-character realtime editor (GDocs).

Page 23: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

In the following example we send the character “a”.

Page 24: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

1. Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.82. Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.33. Accept-Encoding:gzip,deflate,sdch4. Accept-Language:en-US,en;q=0.85. Cache-Control:max-age=06. Connection:keep-alive7. Host:www.myhost.com8. User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.5 Safari/537.17

1. { “c”: “a” }

Headers

Body (JSON obj)

Page 25: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

HTTP/1.1 overhead: 370~ bytes per character. Boo.

Page 26: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

This only considers sending data.

Page 27: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

How ‘bout getting data?

Page 28: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

We poll the server through a GET request

Page 29: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

When the server responds, we send another one.

Page 30: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

And another one.

Page 31: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

…and another one. Boo.

Page 32: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

If the server has no data to send us, we would be generating a LOT of traffic.

Page 33: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

Instead, we make the server wait a bit if it has no data.

Page 34: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

This is what we call long-polling.

Page 35: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

Pseudo-code time.

Page 36: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

function send(data){ var xhr = new XMLHttpRequest(); xhr.open(‘POST’, ‘/’, false); xhr.send(data);}function get(fn) { var xhr = new XMLHttpRequest(); xhr.open(‘GET’, ‘/’, false); xhr.send(data); xhr.onreadystatechange = function(){ if (200 == xhr.status) { fn(); // send data to user get(); // restart poll } }}

Page 37: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

Most applications need to send data in a particular order.

Page 38: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

For our example, the order that the user types.

Page 39: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

Therefore, to replicate socket semantics we need to implement buffering. Boo.

Page 40: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

For example, the user types a then b c d every 100ms.

Page 41: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

If an existing send() is in-flight…

Page 42: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

We accumulate the other data packets in an array.

Page 43: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

Then we send that over when the server replies.

Page 44: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

But instead of just sending one request per character.

Page 45: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

We try to create a data packet with “b” “c” and “d” to minimize the request headers traffic.

Page 46: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

1. Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.82. Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.33. Accept-Encoding:gzip,deflate,sdch4. Accept-Language:en-US,en;q=0.85. Cache-Control:max-age=06. Connection:keep-alive7. Host:www.myhost.com8. User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.5 Safari/537.17

1. [{ “c”: “b” }, { “c”: “c” }, { “c”: “d” }]

Headers

Body (JSON Array)

Page 47: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

This means, however, that we need a protocol.

Page 48: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

A protocol on top of a protocol (HTTP).

Page 49: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

Server and client need to agree that the data is not simply the request body, but within it.

Page 50: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

This is a lot of work before you can focus on your app!

Page 51: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

This has been a common trend in web development.

Page 52: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

Need rounded corners?

Page 53: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

<div class=”wrap-outer”> <div class=”wrap”> <div class=”wrap-inner”> <div class=”content”> </div> </div> </div></div>

Circa 2001

.wrap-outer { background: …; padding: …;}.wrap { background: …; padding: …;}

.wrap-inner { background: …; padding: …;}

Page 54: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

<div class=”content”></div>

Now

.content { border-radius: 3px;}

Page 55: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

For the realtime web…

Page 56: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

Circa 2001

- Data buffering on server within GET polls.- Data buffering on client.- JSON protocol or equivalent.- XMLHttpRequest fallbacks- Cross-domain tricks- …

Page 57: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

Now

- WebSocket!

Page 58: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

Simpler client side API.

Page 59: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

var ws = new WebSocket();ws.onopen = function(){};ws.onclose = function(){};ws.onmessage = function(){};

Page 60: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

Light-weight protocol.

Page 61: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

Instead of sending many HTTP requests.

Page 62: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

Browser sends one that contains a header: Upgrade: WebSocket

Page 63: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

The connection is then taken over.

Page 64: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

Like TCP but unlike HTTP, it’s bi-directional.

Page 65: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

We can send and receive over the same socket.

Page 66: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

In terms of our realtime app example…

Page 67: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

WebSocket overhead: 2-5~* bytes per character.* depending on spec

Page 68: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

But WS is buggy on mobile, unavailable in older browsers, not understood by all middleware, breaks often without SSL.

Page 69: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

Meet engine.io, the data transport engine of socket.io

Page 70: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

var ws = new eio.Socket();ws.onopen = function(){};ws.onclose = function(){};ws.onmessage = function(){};

Page 71: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

Same API, long-polling first, upgrades to WS if possible.

Page 72: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

The main advantage of WS is lightweight framing!

Page 73: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

Most of the benefits that WS offers, like lower-bandwidth, would still benefit XMLHttpRequest.

Page 74: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

Meet SPDY.

Page 75: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

Headers overhead?

Page 76: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

“SPDY compresses request and response HTTP headers, resulting in fewer packets and fewer bytes transmitted.”http://www.chromium.org/spdy/spdy-whitepaper

Page 77: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

TCP overhead?

Page 78: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

“SPDY allows for unlimited concurrent streams over a single TCP connection.”http://www.chromium.org/spdy/spdy-whitepaper

Page 79: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

SPDY works transparently to your app.

Page 80: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

SPDY assumes SSL.

Page 81: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

Just upgrade your SSL terminator or load balancer and reap the benefits!

Page 82: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

In other words, if you host your app on Heroku…

Page 83: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

Keep doing what you’re doing, and wait for the upgrade.

Page 84: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

But wait, many apps still need socket-like semantics.

Page 85: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

I want to write “socket.send(‘data’);” instead of “new XMLHttpRequest”

Page 86: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

I’m not even sending XML!@!!@

Page 87: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

Solution: WebSocket layering over SPDY/3.

Page 88: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

“With this protocol, WebSocket API get both benefits of usable bi-directional communication API, and a fast, secure, and scalable multiplexing mechanism on the top of SPDY”https://docs.google.com/document/d/1zUEFzz7NCls3Yms8hXxY4wGXJ3EEvoZc3GihrqPQcM0/edit#

Page 89: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

Currently a draft.

Page 90: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

SPDY/3 is currently experimental and available through chrome://flags.

Page 91: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

Solution until the ideal world occurs: engine.io

Page 92: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

Moving forward… Most applications are not data-packet oriented.

Page 93: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

socket.io builds on top of engine.io to offer easy-to-use realtime events for everyone.

Page 94: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

var socket = io.connect();socket.on(‘character’, function(){ // render!});socket.on(‘chat message’, function(){ // render!});socket.emit(‘ready!’);

Page 95: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

The goal is to not just focus on the speed of data transfer but also speed of development.

Page 96: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

While ensuring the reliability that the data can be exchanged in the fastest way, in every network, on every device.

Page 97: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

What’s next?

Page 98: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

- Raw TCP/UDP sockets?

Page 99: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

chrome.experimental.socket.create('tcp', '127.0.0.1', 8080, function(socketInfo) { chrome.experimental.socket.connect(socketInfo.socketId, function (result) { chrome.experimental.socket.write(socketInfo.socketId, "Hello, world!"); });});

Page 100: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

For now, only for extensions.

Page 101: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

- Removing the server out of the equation.

Page 102: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

WebRTC PeerConnection.

Page 103: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

Currently called “webkitDeprecatedPeerConnection”

Page 104: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

Let’s be patient!

Page 105: The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond · The realtime web: HTTP/1.1 to WebSocket, SPDY and beyond Guillermo Rauch @ QCon.November 2012.

The end.