Socket.IO

16,015 views
15,754 views

Published on

Presentation from nodecamp.eu

Published in: Technology, Education

Socket.IO

  1. 1. GETTING DIRTY WITH 0.7SOCKET.IO
  2. 2. HELLO > WHOAMI
  3. 3. { "name": "socket.io" , "version": "0.7.0" , "description": "Real time apps made cross-browser & easy with a WebSocket-like API" , "keywords": ["websocket", "realtime", "socket.io", "comet", "ajax"] , "author": "Guillermo Rauch <guillermo@learnboost.com>" , "contributors": [ { "name": "Guillermo Rauch", "email": "rauchg@gmail.com" } , { "name": "Arnout Kazemier", "email": "info@3rd-eden.com" } ] , "repository":{ "type": "git" , "url": "https://github.com/LearnBoost/Socket.IO-node.git" } , "dependencies": {} , "main": "index" , "engines": { "node": ">= 0.4.0" }}
  4. 4. STALK ME ON TWITTER@3rdEden FORK ME ON GITHUB@3rd-Eden
  5. 5. WHAT IS SOCKET.IO
  6. 6. open source
  7. 7. REAL TIME
  8. 8. DIRTY
  9. 9. FAST
  10. 10. F*CKING AWESOME
  11. 11. CROSS BROWSER
  12. 12. CROSS BROWSERINCLUDING MOBILE & INTERNET EXPLORER 5
  13. 13. CROSS BROWSER ORLY? YA RLY
  14. 14. web socket
  15. 15. web socketflash socket
  16. 16. web socketflash sockethtml file (forever iframe)
  17. 17. web socketflash sockethtml file (forever iframe)xhr multipart
  18. 18. web socketflash sockethtml file (forever iframe)xhr multipartxhr polling
  19. 19. web socketflash sockethtml file (forever iframe)xhr multipartxhr pollingjsonp polling
  20. 20. community WATCHERS 2750+ FORKS 250+ PULL REQUESTS 110+GROUPS MEMBERS 1000~
  21. 21. NODE CAMP USERSY U NO FORK
  22. 22. WHATʼS NEW IN 0.7THE LESSONS WE LEARNED FROM 0.6
  23. 23. COMPLETE API REWRITE
  24. 24. var io = require(ʻsocket.ioʼ) , http = require(ʻhttpʼ);var s = http.createServer(function(q,r){r.writeHead(200);r.end(ʻsupʼ)});s.listen(80)io.listen(s); // uses existing server
  25. 25. var io = require(ʻsocket.ioʼ) , http = require(ʻhttpʼ);var s = http.createServer(function(q,r){r.writeHead(200);r.end(ʻsupʼ)});s.listen(80)io.listen(s); // uses existing servervar io = require(ʻsocket.ioʼ);io.listen(80); // creates one for us
  26. 26. var io = require(ʻsocket.ioʼ).listen();// express styled configurationio.configure(ʻdevelopmentʼ, function(){ io.set(ʻlog levelʼ, 3);});
  27. 27. MULTIPLEPROCESSES
  28. 28. NEW PROTOCOL
  29. 29. MESSAGE FLAGS FIRE AND FORGET, JSON NEW PROTOCOL
  30. 30. io.sockets.on(ʻconnectionʼ, function (socket) { socket.volatile.send(ʻpew pewʼ); socket.json.send([{nodecamp:ʻftwʼ}]);}; NEW PROTOCOL
  31. 31. ACKNOWLEDGEMENTS BETWEEN CLIENT & SERVER, SERVER & CLIENT NEW PROTOCOL
  32. 32. // server sideio.sockets.on(ʻconnectionʼ, function (socket) { socket.send(ʻbyeʼ, function () { // ack });});// client sidevar socket = io.connect();socket.send(ʻhiʼ, function () { // ack}); NEW PROTOCOL
  33. 33. NAMESPACING MULTIPLEXING NEW PROTOCOL
  34. 34. // server sideio.sockets.on(ʻconnectionʼ, function (socket) { socket.send(ʻbyeʼ, function () { // ack });});// client sidevar socket = io.connect();socket.send(ʻhiʼ, function () { // ack}); NEW PROTOCOL
  35. 35. HANDSHAKINGFUCK YEAH, SESSIONS SUPPORT NEW PROTOCOL
  36. 36. EVENTS NEW PROTOCOL
  37. 37. CODE SHARINGMODULES ARE REUSED ON THE CLIENT & SERVER
  38. 38. TESTINGBOTH FOR THE CLIENT AND THE SERVER
  39. 39. “ONE MORE THING™” © STEVE JOBS
  40. 40. RELEASE THIS WEEK
  41. 41. Q ATALK NERDY TO ME
  42. 42. presentation.end(‘thanks’);

×