websockets in nodejs

10

Click here to load reader

Upload: bodokaiser

Post on 11-May-2015

569 views

Category:

Technology


1 download

DESCRIPTION

Talk from berlinjs 18. April 2013

TRANSCRIPT

Page 1: WebSockets in nodejs

How to implement WebSockets

in nodejs

Freitag, 19. April 13

Page 2: WebSockets in nodejs

Why actually implement a protocol?

bad support

too much time

want to learn more

Freitag, 19. April 13

Page 3: WebSockets in nodejs

WebSocket Overview

http upgrade

data framing

Freitag, 19. April 13

Page 4: WebSockets in nodejs

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

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

Freitag, 19. April 13

Page 7: WebSockets in nodejs

Architecture: First Take...

Socket

WebSocketFrame

WebSocket

WebSocketBase

WebSocketUpgrade

WebSocketServer WebSocketClient

Freitag, 19. April 13

Page 8: WebSockets in nodejs

Freitag, 19. April 13

Page 9: WebSockets in nodejs

Architecture: Second Take

Socket

WebSocketCore

WebSocketSocket

WebSocketUpgrade

WebSocketServer

Incoming Outgoing

WebSocketParser

Freitag, 19. April 13

Page 10: WebSockets in nodejs

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