Upgrade to Pro — share decks privately, control downloads, hide ads and more …

SockJS - WebSocket Emulation simple, stupid; kr...

majek04
November 14, 2011

SockJS - WebSocket Emulation simple, stupid; krtconf Nov-2011

majek04

November 14, 2011
Tweet

More Decks by majek04

Other Decks in Programming

Transcript

  1. Load Balancer Web server Web server Web server Message bus

    @sockjs http://sockjs.org github.com/sockjs Tuesday, 8 November 11
  2. #sockjs WebSockets hixie-75 4 5.0.0 hixie-76 4 (disabled) 6 5.0.1

    11 (disabled) hybi-07 6 hybi-10 7 14 10-dev hybi-17 16-dev Tuesday, 8 November 11
  3. #sockjs WebSockets hixie-75 4 5.0.0 hixie-76 4 (disabled) 6 5.0.1

    11 (disabled) hybi-07 6 hybi-10 7 14 10-dev hybi-17 16-dev { { Tuesday, 8 November 11
  4. #sockjs FF and Proxies CONNECT sockjs1.popcnt.org:80 HTTP/1.1 Host: sockjs1.popcnt.org Proxy-Connection:

    keep-alive GET /echo/855/duzzy2p1/websocket HTTP/1.1 Upgrade: WebSocket Connection: Upgrade Host: sockjs1.popcnt.org Origin: http://sockjs.popcnt.org Sec-WebSocket-Key1: 22p/ D"47900%n7 r90. Sec-WebSocket-Key2: m49" 5 f 24772 Ra GET /echo/070/lm6wwjpr/websocket HTTP/1.1 Host: sockjs1.popcnt.org User-Agent: [...] Gecko/20100101 Firefox/6.0.2 Accept: text/html,application/xhtml [...] Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip, deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Sec-WebSocket-Version: 7 Sec-WebSocket-Origin: http://sockjs.popcnt.org Sec-WebSocket-Key: bzG4fOYXabSiy42uFj6vjA== Pragma: no-cache Cache-Control: no-cache Upgrade: websocket Connection: Upgrade HTTP/1.0 400 Bad Request Server: squid/2.7.STABLE9 Date: Wed, 21 Sep 2011 06:16:10 GMT Content-Type: text/html Content-Length: 1943 X-Squid-Error: ERR_INVALID_REQ 0 X-Cache: MISS from mrstu Connection: close Tuesday, 8 November 11
  5. #sockjs SockJS 1. WebSocket like API 2. Fallbacks 3. Cross

    domain support 4. Scalability explained 5. Specified protocol, polyglot 6. No messaging model Tuesday, 8 November 11
  6. #sockjs SockJS 1. WebSocket like API 2. Fallbacks 3. Cross

    domain support 4. Scalability explained 5. Specified protocol, polyglot 6. No messaging model Tuesday, 8 November 11
  7. #sockjs WebSocket like API <script> var sock = new SockJS('http://mydomain.com/my_prefix');

    sock.onopen = function() { console.log('open'); }; sock.onmessage = function(e) { console.log('message', e.data); }; sock.onclose = function() { console.log('close'); }; </script> Tuesday, 8 November 11
  8. #sockjs WebSocket like API var http = require('http'); var sockjs

    = require('sockjs'); var echo = sockjs.createServer(sockjs_opts); echo.on('connection', function(conn) { conn.on('data', function(message) { conn.write(message); }); conn.on('close', function() {}); }); var server = http.createServer(); echo.installHandlers(server, {prefix:'[/]echo'}); server.listen(9999, '0.0.0.0'); Tuesday, 8 November 11
  9. #sockjs SockJS 1. WebSocket like API 2. Fallbacks 3. Cross

    domain support 4. Scalability explained 5. Specified protocol, polyglot 6. No messaging model Tuesday, 8 November 11
  10. #sockjs SockJS 1. WebSocket like API 2. Fallbacks 3. Cross

    domain support 4. Scalability explained 5. Specified protocol, polyglot 6. No messaging model Tuesday, 8 November 11
  11. #sockjs Cross domain Load Balancer Web server Web server Web

    server Message bus Tuesday, 8 November 11
  12. #sockjs Cross domain Load Balancer Web server Web server Web

    server Database Load Balancer Async server Message bus Tuesday, 8 November 11
  13. #sockjs SockJS 1. WebSocket like API 2. Fallbacks 3. Cross

    domain support 4. Scalability explained 5. Specified protocol, polyglot 6. No messaging model Tuesday, 8 November 11
  14. #sockjs Load blancer Load Balancer Web server Web server Web

    server Message bus Tuesday, 8 November 11
  15. #sockjs ? Load blancer Load Balancer Web server Web server

    Web server Message bus Tuesday, 8 November 11
  16. #sockjs Sticky sessions Load Balancer Web server Web server Web

    server Message bus • prefix based • JSESSIONID cookie Tuesday, 8 November 11
  17. #sockjs Load Balancer Web server Web server Web server Database

    Load Balancer Async server Message bus Deployment Tuesday, 8 November 11
  18. #sockjs ws:// Load Balancer Web server Web server Web server

    Message bus ws:// ws:// Load Balancer SockJS proxy Deployment Tuesday, 8 November 11
  19. #sockjs SockJS 1. WebSocket like API 2. Fallbacks 3. Cross

    domain support 4. Scalability explained 5. Specified protocol, polyglot 6. No messaging model Tuesday, 8 November 11
  20. #sockjs Polyglot • Server side: • simple, testable • Supported:

    • Node.js, Erlang, LUA, Ruby* Tuesday, 8 November 11
  21. #sockjs SockJS 1. WebSocket like API 2. Fallbacks 3. Cross

    domain support 4. Scalability explained 5. Specified protocol, polyglot 6. No messaging model Tuesday, 8 November 11
  22. #sockjs Load Balancer Web server Web server Web server Database

    Service Web Messaging Service Tuesday, 8 November 11
  23. #sockjs Load Balancer Web server Web server Web server Database

    Service Web Messaging Service Tuesday, 8 November 11
  24. #sockjs Google App Engine • Simplex • No broadcast •

    No presence user App Tuesday, 8 November 11
  25. #sockjs PubNub • Duplex • Broadcast • No permissions •

    No identity subscribe("/topic") publish("/topic") App Tuesday, 8 November 11
  26. #sockjs Pusher • Simplex • Broadcast • Permissions * •

    Identity * • Presence * App publish("/topic") subscribe("/topic") Tuesday, 8 November 11
  27. #sockjs 1. Authorisation 2. Value + updates 3. Presence App

    subscribe("/chat") subscribe("/roster") index.html Tuesday, 8 November 11
  28. #sockjs App 2. identity and permissions 4. 3. token token

    1. GET Authorization Tuesday, 8 November 11
  29. #sockjs V+U: Application subscribe("/chat") …updates from "chat"… get historical data

    for "/chat" App [...] <dwww> Version/11.51 <majek> ah, boring then. <dwww> i copypasted what qunit page reports <dwww> ;) <majek> No browser works on your computer :) Tuesday, 8 November 11
  30. #sockjs V+U: Application } subscribe("/chat") …updates from "chat"… get historical

    data for "/chat" App [...] <dwww> Version/11.51 <majek> ah, boring then. <dwww> i copypasted what qunit page reports <dwww> ;) <majek> No browser works on your computer :) Tuesday, 8 November 11
  31. #sockjs Service? Load Balancer Web server Web server Web server

    Database Service Tuesday, 8 November 11