websockets in nodejs
DESCRIPTION
Talk from berlinjs 18. April 2013TRANSCRIPT
![Page 1: WebSockets in nodejs](https://reader038.vdocuments.mx/reader038/viewer/2022100506/554fb03eb4c905ad218b51e5/html5/thumbnails/1.jpg)
How to implement WebSockets
in nodejs
Freitag, 19. April 13
![Page 2: WebSockets in nodejs](https://reader038.vdocuments.mx/reader038/viewer/2022100506/554fb03eb4c905ad218b51e5/html5/thumbnails/2.jpg)
Why actually implement a protocol?
bad support
too much time
want to learn more
Freitag, 19. April 13
![Page 3: WebSockets in nodejs](https://reader038.vdocuments.mx/reader038/viewer/2022100506/554fb03eb4c905ad218b51e5/html5/thumbnails/3.jpg)
WebSocket Overview
http upgrade
data framing
Freitag, 19. April 13
![Page 4: WebSockets in nodejs](https://reader038.vdocuments.mx/reader038/viewer/2022100506/554fb03eb4c905ad218b51e5/html5/thumbnails/4.jpg)
http upgradeRequest
GET ws://localhost:3000/ HTTP/1.1Host: localhost:3000Origin: http://localhost:3000Upgrade: websocketConnection: UpgradeSec-WebSocket-Key: balUGY40R1lyHPJZf3XHqQ==Sec-WebSocket-Extensions: x-webkit-deflate-frameSec-WebSocket-Protocol: chatSec-WebSocket-Version: 13
Response
HTTP/1.1 101 Switching ProtocolsUpgrade: websocketConnection: UpgradeSec-WebSocket-Accept: GCPOtLmN+iCXPREPmHfgCKsCllU=Sec-WebSocket-Extensions: x-webkit-deflate-frameSec-WebSocket-Protocol: chatSec-WebSocket-Version: 13
Freitag, 19. April 13
![Page 5: WebSockets in nodejs](https://reader038.vdocuments.mx/reader038/viewer/2022100506/554fb03eb4c905ad218b51e5/html5/thumbnails/5.jpg)
data framing
10000001
00000101
01001000
01100101
01101100
01101100
01101111
FIN: BooleanRSV1: BooleanRSV2: BooleanRSV3: BooleanOPCODE: NumberMASK: BooleanLENGTH: NumberMASKING: BufferPAYLOAD: Buffer
unmasked text frame containing „Hello“
0x81
0x05
0x48
0x65
0x6c
0x6c
0x6c
H
e
l
l
oFreitag, 19. April 13
![Page 6: WebSockets in nodejs](https://reader038.vdocuments.mx/reader038/viewer/2022100506/554fb03eb4c905ad218b51e5/html5/thumbnails/6.jpg)
Freitag, 19. April 13
![Page 7: WebSockets in nodejs](https://reader038.vdocuments.mx/reader038/viewer/2022100506/554fb03eb4c905ad218b51e5/html5/thumbnails/7.jpg)
Architecture: First Take...
Socket
WebSocketFrame
WebSocket
WebSocketBase
WebSocketUpgrade
WebSocketServer WebSocketClient
Freitag, 19. April 13
![Page 8: WebSockets in nodejs](https://reader038.vdocuments.mx/reader038/viewer/2022100506/554fb03eb4c905ad218b51e5/html5/thumbnails/8.jpg)
Freitag, 19. April 13
![Page 9: WebSockets in nodejs](https://reader038.vdocuments.mx/reader038/viewer/2022100506/554fb03eb4c905ad218b51e5/html5/thumbnails/9.jpg)
Architecture: Second Take
Socket
WebSocketCore
WebSocketSocket
WebSocketUpgrade
WebSocketServer
Incoming Outgoing
WebSocketParser
Freitag, 19. April 13
![Page 10: WebSockets in nodejs](https://reader038.vdocuments.mx/reader038/viewer/2022100506/554fb03eb4c905ad218b51e5/html5/thumbnails/10.jpg)
End
https://github.com/bodokaiser/node-websockets
only use ws for chat-like use-cases
use streams where you can
don`t worry v8 is fast enough
Freitag, 19. April 13