WebSockets by Bodo Kaiser
Aug 28, 2014
WebSocketsby Bodo Kaiser
What are WebSockets?
WebSockets allow bidirectional communication over HTTP!
HTTPServer
Client
GET / HTTP/1.1Host: localhostAccept: */*
HTTP/1.1 200 OKContent-Type: text/plainContent-Length: 12
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: …
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
WebSockets in node.js
socket.io by learn boost fallback support, high level api (e.g. events)
!ws by einaros
„fastest“ websocket implementation
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
Designhttp.Server
„upgrade“ Event
walve.Server
walve.Response
walve.Socket
walve.Socket
walve.Incoming walve.Outgoing
„response“ Event
Some Router / Web Framework
Code Examples
Visit http://github.com/bodokaiser/node-walve ! !
!
Do not forget to leave a Start :)
Performance (Hello World)Hello World
0,000
1,000
2,000
3,000
4,000
5,000
ws walve
Performance (Small Image)Small Image
60,000
70,000
80,000
90,000
100,000
110,000
ws walve
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
Performance (Memory Consumption)Memory Consumption
0,0
100,0
200,0
300,0
400,0
500,0
walve ws
Further Thoughts
1. Reliability !
2. Extendability !
3. Future development !
4. Mobile Usage (ProTip)
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
Thanks and Q&A
Follow me on twitter @bodojs !
Star my projects on github github.com/bodokaiser