Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
WebSockets & Ruby EventMachine




  HTML5 Web sockets
               Polling



      Long-polling



       Web socket

...
WebSockets & Ruby EventMachine




                    Use cases

                    • Chat (lame)
                    • ...
WebSockets & Ruby EventMachine



WebSockets DOM API




                                 Ismael Celis   new bamboo
WebSockets & Ruby EventMachine




WebSockets handshake
           Request




           Response




            Profit!
...
WebSockets & Ruby EventMachine




Messages

                 "x00Hello Worldxff"




                                   I...
WebSockets & Ruby EventMachine




Real Time HTML




                                 Ismael Celis   new bamboo
WebSockets & Ruby EventMachine




(Ruby) WebSockets server


                    • Speak WebSockets (handshake)
         ...
WebSockets & Ruby EventMachine




EventMachine                     rubyeventmachine.com




                             ...
WebSockets & Ruby EventMachine




EM-WebSocket
github.com/igrigorik/em-websocket




                                    ...
WebSockets & Ruby EventMachine




EM-WebSocket
github.com/igrigorik/em-websocket




                                    ...
WebSockets & Ruby EventMachine



Multiuser




                                 Ismael Celis   new bamboo
WebSockets & Ruby EventMachine




Pick your format
                   STOMP         CONNECT
                             ...
WebSockets & Ruby EventMachine




Custom JSON format

  [
          “user_connected”,               Event name
          ...
WebSockets & Ruby EventMachine




Javascript wrapper




                                 Ismael Celis   new bamboo
WebSockets & Ruby EventMachine




Javascript wrapper




                                 [ “user_message”,
             ...
WebSockets & Ruby EventMachine



Implementation                   gist.github.com/299789




                            ...
WebSockets & Ruby EventMachine



Implementation                   gist.github.com/299789




                            ...
WebSockets & Ruby EventMachine



Implementation                   gist.github.com/299789


                              ...
WebSockets & Ruby EventMachine



Implementation                   gist.github.com/299789




                            ...
WebSockets & Ruby EventMachine




           blog.new-bamboo.co.uk



                                 Ismael Celis   new...
Upcoming SlideShare
Loading in …5
×

Websockets and Ruby EventMachine

27,379 views

Published on

The basics of a WebSockets server in Ruby EventMachine and your own custom JSON protocol for Events-centric WebSockets programming.

See more at http://blog.new-bamboo.co.uk/2010/2/10/json-event-based-convention-websockets

Published in: Technology, Education

Websockets and Ruby EventMachine

  1. 1. WebSockets & Ruby EventMachine HTML5 Web sockets Polling Long-polling Web socket websockets.org/about.html Ismael Celis new bamboo
  2. 2. WebSockets & Ruby EventMachine Use cases • Chat (lame) • Stocks (lame) • Games • Presence • Collaboration • Real-time notifications Ismael Celis new bamboo
  3. 3. WebSockets & Ruby EventMachine WebSockets DOM API Ismael Celis new bamboo
  4. 4. WebSockets & Ruby EventMachine WebSockets handshake Request Response Profit! Ismael Celis new bamboo
  5. 5. WebSockets & Ruby EventMachine Messages "x00Hello Worldxff" Ismael Celis new bamboo
  6. 6. WebSockets & Ruby EventMachine Real Time HTML Ismael Celis new bamboo
  7. 7. WebSockets & Ruby EventMachine (Ruby) WebSockets server • Speak WebSockets (handshake) • Keep connections alive • Performant! • Scalable • Threads? Evented? Ismael Celis new bamboo
  8. 8. WebSockets & Ruby EventMachine EventMachine rubyeventmachine.com Ismael Celis new bamboo
  9. 9. WebSockets & Ruby EventMachine EM-WebSocket github.com/igrigorik/em-websocket Ismael Celis new bamboo
  10. 10. WebSockets & Ruby EventMachine EM-WebSocket github.com/igrigorik/em-websocket Ismael Celis new bamboo
  11. 11. WebSockets & Ruby EventMachine Multiuser Ismael Celis new bamboo
  12. 12. WebSockets & Ruby EventMachine Pick your format STOMP CONNECT login: <username> passcode: <passcode> <message XMPP from=”john@server.com/ruby” to=”jane@server.com/ruby”> <body>Hey Jane!</body> </message> Your own (JSON?) Ismael Celis new bamboo
  13. 13. WebSockets & Ruby EventMachine Custom JSON format [ “user_connected”, Event name { “name” : “Ismael”, “message” : “hello!”, Custom data “total_users” : 10 } ] Ismael Celis new bamboo
  14. 14. WebSockets & Ruby EventMachine Javascript wrapper Ismael Celis new bamboo
  15. 15. WebSockets & Ruby EventMachine Javascript wrapper [ “user_message”, { “name” : “Ismael”, “message” : “hello!” } ] Ismael Celis new bamboo
  16. 16. WebSockets & Ruby EventMachine Implementation gist.github.com/299789 Ismael Celis new bamboo
  17. 17. WebSockets & Ruby EventMachine Implementation gist.github.com/299789 Ismael Celis new bamboo
  18. 18. WebSockets & Ruby EventMachine Implementation gist.github.com/299789 WebSocket Ismael Celis new bamboo
  19. 19. WebSockets & Ruby EventMachine Implementation gist.github.com/299789 Ismael Celis new bamboo
  20. 20. WebSockets & Ruby EventMachine blog.new-bamboo.co.uk Ismael Celis new bamboo

×