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

ActionCable vs. Socket.io at ConFoo

ActionCable vs. Socket.io at ConFoo

How do you achieve real time, bi-directional, event-based communications in your apps? The Socket.io library is tested and true. ActionCable, new with Ruby on Rails version 5, is a challenger. Which solution is better, and why?

This presentation compares Socket.io and ActionCable (included w/Ruby on Rails version 5).

2769d4f1f9abeb4dd2438ff636a9e4dc?s=128

Ray Hightower

December 07, 2016
Tweet

Transcript

  1. ActionCable vs. Socket.io @RayHightower ConFoo - Dec 5-7, 2016 Vancouver,

    BC Canada
  2. What? Why? Examples. Comparison.

  3. ActionCable is… •Real time. •Full duplex. •Event based.

  4. Half Duplex Walkie-Talkie Full Duplex Phone

  5. HTTP is stateless.

  6. None
  7. https://xkcd.com/869/

  8. WebSocket Protocol

  9. REmote DIctionary Server

  10. In-memory Key-value store Dictionary Hash {

  11. pub/sub

  12. None
  13. Channels: Clients Rooms: Server

  14. Create the app.

  15. None
  16. Generate the rooms controller.

  17. None
  18. Generate the channel.

  19. None
  20. Create a home for the messages in the database.

  21. None
  22. Remember the migration!

  23. None
  24. 1 Rails.application.routes.draw do 2 get 'rooms/show' 3 4 end 1

    Rails.application.routes.draw do 2 root to: ‘rooms#show' 3 4 end config/routes.rb (before & after)
  25. 1 class RoomsController < ApplicationController 2 def show 3 @messages

    = Message.all 4 end 5 end app/controllers/rooms_controller.rb (before & after) 1 class RoomsController < ApplicationController 2 def show 3 end 4 end
  26. app/channels/rooms_channel.rb 1 # Be sure to restart your server when

    you modify… 2 class RoomChannel < ApplicationCable::Channel 3 def subscribed 4 # stream_from "some_channel" 5 end 6 7 def unsubscribed 8 # Any cleanup needed when channel is unsubscribed 9 end 10 11 def speak 12 end 13 end
  27. None
  28. The Remarkable Journey of a Single Web Request by Aaron

    Kalin https://windycityrails.com/videos/2015/#9
  29. None
  30. Another chat app?

  31. Gartner Hype Cycle Image by Jeremy Kemp https://commons.wikimedia.org/wiki/File:Gartner_Hype_Cycle.svg

  32. Gartner Hype Cycle ActionCable Slope of Enlightenment?

  33. None
  34. None
  35. +

  36. WebSockets and Robotics

  37. Remotely Operated Vehicle

  38. None
  39. None
  40. None
  41. None
  42. None
  43. None
  44. None
  45. None
  46. None
  47. None
  48. None
  49. Browser BeagleBone Black Arduino Socket.io Serial Node.js Chrome C++

  50. Browser BeagleBone Black Arduino ActionCable Serial Ruby Chrome C++

  51. Comparison

  52. •ActionCable is… •Socket.io is…

  53. YACA OpenROV vs.

  54. Fitness for a particular purpose.

  55. Thanks! RayHightower.com