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

ActionCable vs. Socket.io at ConFoo

Ray Hightower
December 07, 2016

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).

Ray Hightower

December 07, 2016
Tweet

More Decks by Ray Hightower

Other Decks in Technology

Transcript

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

    View full-size slide

  2. What? Why?
    Examples.
    Comparison.

    View full-size slide

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

    View full-size slide

  4. Half Duplex
    Walkie-Talkie
    Full Duplex
    Phone

    View full-size slide

  5. HTTP is
    stateless.

    View full-size slide

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

    View full-size slide

  7. WebSocket
    Protocol

    View full-size slide

  8. REmote
    DIctionary
    Server

    View full-size slide

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

    View full-size slide

  10. Channels: Clients
    Rooms: Server

    View full-size slide

  11. Create the app.

    View full-size slide

  12. Generate the
    rooms controller.

    View full-size slide

  13. Generate the
    channel.

    View full-size slide

  14. Create a home for
    the messages in
    the database.

    View full-size slide

  15. Remember the
    migration!

    View full-size slide

  16. 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)

    View full-size slide

  17. 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

    View full-size slide

  18. 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

    View full-size slide

  19. The Remarkable Journey
    of a Single Web Request
    by Aaron Kalin
    https://windycityrails.com/videos/2015/#9

    View full-size slide

  20. Another chat app?

    View full-size slide

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

    View full-size slide

  22. Gartner Hype Cycle
    ActionCable
    Slope of Enlightenment?

    View full-size slide

  23. WebSockets
    and
    Robotics

    View full-size slide

  24. Remotely
    Operated
    Vehicle

    View full-size slide

  25. Browser
    BeagleBone Black
    Arduino
    Socket.io
    Serial
    Node.js
    Chrome C++

    View full-size slide

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

    View full-size slide

  27. •ActionCable is…
    •Socket.io is…

    View full-size slide

  28. YACA
    OpenROV
    vs.

    View full-size slide

  29. Fitness for a
    particular
    purpose.

    View full-size slide

  30. Thanks!
    RayHightower.com

    View full-size slide