![Page 1: WebSockets - Today, in the Past, in Future and in Production](https://reader033.vdocuments.us/reader033/viewer/2022051608/53fe34868d7f72c4108b45ff/html5/thumbnails/1.jpg)
WebSocketsby Bodo Kaiser
![Page 2: WebSockets - Today, in the Past, in Future and in Production](https://reader033.vdocuments.us/reader033/viewer/2022051608/53fe34868d7f72c4108b45ff/html5/thumbnails/2.jpg)
What are WebSockets?
WebSockets allow bidirectional communication over HTTP!
![Page 3: WebSockets - Today, in the Past, in Future and in Production](https://reader033.vdocuments.us/reader033/viewer/2022051608/53fe34868d7f72c4108b45ff/html5/thumbnails/3.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022051608/53fe34868d7f72c4108b45ff/html5/thumbnails/4.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022051608/53fe34868d7f72c4108b45ff/html5/thumbnails/5.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022051608/53fe34868d7f72c4108b45ff/html5/thumbnails/6.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022051608/53fe34868d7f72c4108b45ff/html5/thumbnails/7.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022051608/53fe34868d7f72c4108b45ff/html5/thumbnails/8.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022051608/53fe34868d7f72c4108b45ff/html5/thumbnails/9.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022051608/53fe34868d7f72c4108b45ff/html5/thumbnails/10.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022051608/53fe34868d7f72c4108b45ff/html5/thumbnails/11.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022051608/53fe34868d7f72c4108b45ff/html5/thumbnails/12.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022051608/53fe34868d7f72c4108b45ff/html5/thumbnails/13.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022051608/53fe34868d7f72c4108b45ff/html5/thumbnails/14.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022051608/53fe34868d7f72c4108b45ff/html5/thumbnails/15.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022051608/53fe34868d7f72c4108b45ff/html5/thumbnails/16.jpg)
Thanks and Q&A
Follow me on twitter @bodojs !
Star my projects on github github.com/bodokaiser