41
Working with WebSockets in Perl Viacheslav Tykhanovskyi (vti) October 19, 2012

Working with WebSockets in Perl

  • Upload
    vti

  • View
    3.975

  • Download
    6

Embed Size (px)

DESCRIPTION

WebSockets are the the juicy part of the HTML5 specification. They promise the solution to the edgy real-time web communication. But how widespread are they and what are the technologies that can safely replace them in older browsers? This talk is about the current state of WebSockets and how to use them from Perl applications with some fun live examples.

Citation preview

Working with WebSockets in Perl

Viacheslav Tykhanovskyi (vti)

October 19, 2012

THIS IS NOT IN RUSSIA!!1

Brazil 2012

Serious stuff

HTML5First draft in 2008

WebSocketsfull duplex and persistent

tcp connections

HTTP/1.1 handshakeClient – Frames – Server

var ws = new WebSocket(’ws://localhost’);

ws.onmessage = function(e) {

var message = e.data;

alert(’Got new message: ’ + message);

};

ws.send(’Hello, world!’);

RFC 6455

Once upon a time...

Draft 75 (hixie)

Draft 76 (00-hybi)Sec- and challenge (proxy fail)

10-hybiNew frame!

\x00DATA\xff

0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1+−+−+−+−+−−−−−−−+−+−−−−−−−−−−−−−+−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−+|F |R|R|R| opcode |M| Payload l e n | Extended pay load l e n g t h || I |S |S |S | (4 ) |A| (7 ) | (16/63) ||N|V|V|V| |S | | ( i f pay load l e n ==126/127) || | 1 | 2 | 3 | |K| | |+−+−+−+−+−−−−−−−+−+−−−−−−−−−−−−−+− − − − − − − − − − − − − − − +| Extended pay load l e n g t h cont inued , i f pay load l e n == 127 |+ − − − − − − − − − − − − − − − +−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−+| |Masking−key , i f MASK s e t to 1 |+−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−+−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−+| Masking−key ( con t i nued ) | Payload Data |+−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− − − − − − − − − − − − − − − +: Pay load Data con t i nued . . . :+ − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − +| Payload Data con t i nued . . . |+−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−+

Sec-WebSocket-Version: 8

17-hybi (RFC 6455)Sec-WebSocket-Version: 13

BrowsersThe things start to get serious

Dra f t #75−−−−−−−−−Chrome 5S a f a r i 5 . 0Andro id 2 . x

Dra f t #76−−−−−−−−−F i r e f o x 4b ( d i s a b l e d )S a f a r i 5 . 0 . 2Chrome 6−13Opera 10 .70 ( d i s a b l e d )

iOS 4 .2

Dra f t #10−−−−−−−−−F i r e f o x 10Chrome 14

RFC 6455−−−−−−−−Chrome 14+F i r e f o x 10+IE 10

Special cases

Firefox 7Connection:keep-alive, Upgrade

HAProxyRead handshake headersWrite handshake headers

Read the body partAccept the handshake

Perl implementations

MojoliciousRFC 6455

Protocol::WebSocket (Dancer,Net::Async::WebSocket, Web::Hippie)

75, 76 (00), 10, 17, RFC 6455 + browserworkarounds

WebSocket fallbacks

Flashhttps://github.com/gimite/web-socket-jsRequires policy server (843 port or inline)

Socket.IOhttp://socket.io/

PocketIO — Perl implementation

SockJShttps://github.com/sockjs/sockjs-client

SockJS-Perl — Perl implementation

Examples

1. Protocol::WebSocket console

2. Showmethedrawing

3. Showmetheshell

Obrigado!