Websockets Bring Light at the End of the Tunnel · THINK. CODE. COLLABORATE. spiria.com Websockets...

22
THINK. CODE. COLLABORATE. spiria.com Websockets Bring Light at the End of the Tunnel JOEL LORD Presented by Node PDX – June 20 th , 2016

Transcript of Websockets Bring Light at the End of the Tunnel · THINK. CODE. COLLABORATE. spiria.com Websockets...

Page 1: Websockets Bring Light at the End of the Tunnel · THINK. CODE. COLLABORATE. spiria.com Websockets Bring Light at the End of the Tunnel JOEL LORD resente y Node PDX – June 20th,

THINK. CODE. COLLABORATE.

spiria.com

Websockets Bring Light at the End of the Tunnel

JOEL LORDPresented by

Node PDX – June 20th, 2016

Page 2: Websockets Bring Light at the End of the Tunnel · THINK. CODE. COLLABORATE. spiria.com Websockets Bring Light at the End of the Tunnel JOEL LORD resente y Node PDX – June 20th,

Aboot me, eh?

JOEL LORD

- Javascript junkie- Tinkerer- Technology enthusiast

@joel__lord #nodepdx

Page 3: Websockets Bring Light at the End of the Tunnel · THINK. CODE. COLLABORATE. spiria.com Websockets Bring Light at the End of the Tunnel JOEL LORD resente y Node PDX – June 20th,

WEB SOCKETS

What are they?

Page 4: Websockets Bring Light at the End of the Tunnel · THINK. CODE. COLLABORATE. spiria.com Websockets Bring Light at the End of the Tunnel JOEL LORD resente y Node PDX – June 20th,

WebSocket is a protocol providing full-duplex communications channels over a single TCP connection.

The WebSocket protocol was standardized by the IETF as RFC 6455 in

2011, and the WebSocketAPI in Web IDL is being standardized by the W3C.

@joel__lord #nodepdx

Page 5: Websockets Bring Light at the End of the Tunnel · THINK. CODE. COLLABORATE. spiria.com Websockets Bring Light at the End of the Tunnel JOEL LORD resente y Node PDX – June 20th,

Typical real-timeNORMAL HTTP REQUESTS

@joel__lord #nodepdx

Client

Server

Time

Page 6: Websockets Bring Light at the End of the Tunnel · THINK. CODE. COLLABORATE. spiria.com Websockets Bring Light at the End of the Tunnel JOEL LORD resente y Node PDX – June 20th,

Typical real-timePOLLING

@joel__lord #nodepdx

Client

Server

Time

Page 7: Websockets Bring Light at the End of the Tunnel · THINK. CODE. COLLABORATE. spiria.com Websockets Bring Light at the End of the Tunnel JOEL LORD resente y Node PDX – June 20th,

Typical real-timeLONG-POLLING

@joel__lord #nodepdx

Client

Server

Time

Page 8: Websockets Bring Light at the End of the Tunnel · THINK. CODE. COLLABORATE. spiria.com Websockets Bring Light at the End of the Tunnel JOEL LORD resente y Node PDX – June 20th,

Typical real-timeWEBSOCKETS

@joel__lord #nodepdx

Client

Server

Time

Page 9: Websockets Bring Light at the End of the Tunnel · THINK. CODE. COLLABORATE. spiria.com Websockets Bring Light at the End of the Tunnel JOEL LORD resente y Node PDX – June 20th,

Typical real-timeWHAT ABOUT SERVER-SIDE EVENTS?

@joel__lord #nodepdx

Client

Server

Time

Page 10: Websockets Bring Light at the End of the Tunnel · THINK. CODE. COLLABORATE. spiria.com Websockets Bring Light at the End of the Tunnel JOEL LORD resente y Node PDX – June 20th,

Pros and cons.

Page 11: Websockets Bring Light at the End of the Tunnel · THINK. CODE. COLLABORATE. spiria.com Websockets Bring Light at the End of the Tunnel JOEL LORD resente y Node PDX – June 20th,

Bi-directional data transfersFast Low bandwith Detects connection and disconnection

01PROS

@joel__lord #nodepdx

Page 12: Websockets Bring Light at the End of the Tunnel · THINK. CODE. COLLABORATE. spiria.com Websockets Bring Light at the End of the Tunnel JOEL LORD resente y Node PDX – June 20th,

Lose the caching capabilities built in XHR and HTTPArchitectural changes in the application

02CONS

@joel__lord #nodepdx

Page 13: Websockets Bring Light at the End of the Tunnel · THINK. CODE. COLLABORATE. spiria.com Websockets Bring Light at the End of the Tunnel JOEL LORD resente y Node PDX – June 20th,

WebSockets in the WildREAL WORLD CASES

@joel__lord #nodepdx

- Real time synchronization of data amongst a group of users (trello.com)

- Live feeds (Twitter stream)

- Long server processes and providing ETAs to users

- Multiplayer HTML5 games

- Chat clients (Slack)

Page 14: Websockets Bring Light at the End of the Tunnel · THINK. CODE. COLLABORATE. spiria.com Websockets Bring Light at the End of the Tunnel JOEL LORD resente y Node PDX – June 20th,

Using WebSockets with HTML5ESTABLISHING A CONNECTION

@joel__lord #nodepdx

Page 15: Websockets Bring Light at the End of the Tunnel · THINK. CODE. COLLABORATE. spiria.com Websockets Bring Light at the End of the Tunnel JOEL LORD resente y Node PDX – June 20th,

Using WebSockets with HTML5EVENTS

@joel__lord #nodepdx

Page 16: Websockets Bring Light at the End of the Tunnel · THINK. CODE. COLLABORATE. spiria.com Websockets Bring Light at the End of the Tunnel JOEL LORD resente y Node PDX – June 20th,

Using WebSockets with HTML5SENDING DATA TO THE SERVER

@joel__lord #nodepdx

Page 17: Websockets Bring Light at the End of the Tunnel · THINK. CODE. COLLABORATE. spiria.com Websockets Bring Light at the End of the Tunnel JOEL LORD resente y Node PDX – June 20th,

Getting startedVARIOUS IMPLEMENTATIONS

@joel__lord #nodepdx

- PubNub (cloud)

- Ratchet (php)

- Jetty (Java)

- socket.io (node.js)

Page 18: Websockets Bring Light at the End of the Tunnel · THINK. CODE. COLLABORATE. spiria.com Websockets Bring Light at the End of the Tunnel JOEL LORD resente y Node PDX – June 20th,

Here comes Socket.io!WHAT’S SO COOL ABOUT IT?

@joel__lord #nodepdx

- Server and client-side implementation

- Falls back to long polling when necessary (IE 9 😱)

- Adds features like heartbeats, timeouts, and disconnection support not

provided in WebSocket API

- Easy stuff !

Page 19: Websockets Bring Light at the End of the Tunnel · THINK. CODE. COLLABORATE. spiria.com Websockets Bring Light at the End of the Tunnel JOEL LORD resente y Node PDX – June 20th,

Here comes Socket.io!CLIENT SIDE

@joel__lord #nodepdx

Page 20: Websockets Bring Light at the End of the Tunnel · THINK. CODE. COLLABORATE. spiria.com Websockets Bring Light at the End of the Tunnel JOEL LORD resente y Node PDX – June 20th,

Here comes Socket.io!SERVER SIDE

@joel__lord #nodepdx

Page 21: Websockets Bring Light at the End of the Tunnel · THINK. CODE. COLLABORATE. spiria.com Websockets Bring Light at the End of the Tunnel JOEL LORD resente y Node PDX – June 20th,

LET’S GET SERIOUS

Coding time!

Page 22: Websockets Bring Light at the End of the Tunnel · THINK. CODE. COLLABORATE. spiria.com Websockets Bring Light at the End of the Tunnel JOEL LORD resente y Node PDX – June 20th,

THINK. CODE. COLLABORATE.

spiria.com

The end!

JOEL LORD

Node PDX – June 20th, 2016

Presented by @joel__lord #nodepdx

/joellord