Top Banner
WebSockets by Bodo Kaiser
16

WebSockets - Today, in the Past, in Future and in Production.

Aug 28, 2014

Download

Software

bodokaiser

In the given talk I cover interesting fact about the protocol which provides HTTP bidirectional communication. Starting with the past state of web sockets and their implementation I explain the protocol step by step, present my own stream based WebSocket implementation and compare it to present challengers. To the end I talk about my personal experience with WebSockets and how I predict the future of them.
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: WebSockets - Today, in the Past, in Future and in Production.

WebSocketsby Bodo Kaiser

Page 2: WebSockets - Today, in the Past, in Future and in Production.

What are WebSockets?

WebSockets allow bidirectional communication over HTTP!

Page 3: WebSockets - Today, in the Past, in Future and in Production.

HTTPServer

Client

GET / HTTP/1.1Host: localhostAccept: */*

HTTP/1.1 200 OKContent-Type: text/plainContent-Length: 12

Page 4: WebSockets - Today, in the Past, in Future and in Production.

WSServer

Client

GET / HTTP/1.1Host: localhostUpgrade: websocketConnection: UpgradeSec-WebSocket-Key: …Sec-WebSocket-Version:13

HTTP/1.1 101 Switching…Upgrade: websocketConnection: UpgradeSec-WebSocket-Accept: …

Page 5: WebSockets - Today, in the Past, in Future and in Production.

Frame Encoding

1000 0001 0000 0101 0100 1000 0110 0101 0111 1001

PayloadHeader

H e yF I N

R S V

OP CODE

M A S K

LENGTH

Extended Length Masking

Page 6: WebSockets - Today, in the Past, in Future and in Production.

WebSockets in node.js

socket.io by learn boost fallback support, high level api (e.g. events)

!ws by einaros

„fastest“ websocket implementation

Page 7: WebSockets - Today, in the Past, in Future and in Production.

Walve

- socket.io by learn boost not working, using xhr fallback all the time, cannot read code for PR

!- other ws implementations awful API design, also bad to read

1. Follows node’s core conventions 2. Uses node’s TransformStreams 3. Written in readable JavaScript

Page 8: WebSockets - Today, in the Past, in Future and in Production.

Designhttp.Server

„upgrade“ Event

walve.Server

walve.Response

walve.Socket

walve.Socket

walve.Incoming walve.Outgoing

„response“ Event

Some Router / Web Framework

Page 9: WebSockets - Today, in the Past, in Future and in Production.

Code Examples

Visit http://github.com/bodokaiser/node-walve ! !

!

Do not forget to leave a Start :)

Page 10: WebSockets - Today, in the Past, in Future and in Production.

Performance (Hello World)Hello World

0,000

1,000

2,000

3,000

4,000

5,000

ws walve

Page 11: WebSockets - Today, in the Past, in Future and in Production.

Performance (Small Image)Small Image

60,000

70,000

80,000

90,000

100,000

110,000

ws walve

Page 12: WebSockets - Today, in the Past, in Future and in Production.

Performance (Large Image)Large Image

Wer

teac

hse

2000,000

2400,000

2800,000

3200,000

3600,000

4000,000

4400,000

4800,000

5200,000

5600,000

6000,000

ws walve

Page 13: WebSockets - Today, in the Past, in Future and in Production.

Performance (Memory Consumption)Memory Consumption

0,0

100,0

200,0

300,0

400,0

500,0

walve ws

Page 14: WebSockets - Today, in the Past, in Future and in Production.

Further Thoughts

1. Reliability !

2. Extendability !

3. Future development !

4. Mobile Usage (ProTip)

Page 15: WebSockets - Today, in the Past, in Future and in Production.

ExamplesMessenger

!Simple WebSocket Chat with Image support.

Nearby !

Realtime Tracking with Google Maps and Geolocation.

!http://github.com/bodokaiser/messenger http://github.com/bodokaiser/nearby

Page 16: WebSockets - Today, in the Past, in Future and in Production.

Thanks and Q&A

Follow me on twitter @bodojs !

Star my projects on github github.com/bodokaiser