SlideShare a Scribd company logo
1 of 20
WebSockets & Ruby EventMachine




  HTML5 Web sockets
               Polling



      Long-polling



       Web socket


                         websockets.org/about.html
                                                     Ismael Celis   new bamboo
WebSockets & Ruby EventMachine




                    Use cases

                    • Chat (lame)
                    • Stocks (lame)
                    • Games
                    • Presence
                    • Collaboration
                    • Real-time notifications

                                               Ismael Celis   new bamboo
WebSockets & Ruby EventMachine



WebSockets DOM API




                                 Ismael Celis   new bamboo
WebSockets & Ruby EventMachine




WebSockets handshake
           Request




           Response




            Profit!
                                 Ismael Celis   new bamboo
WebSockets & Ruby EventMachine




Messages

                 "x00Hello Worldxff"




                                   Ismael Celis   new bamboo
WebSockets & Ruby EventMachine




Real Time HTML




                                 Ismael Celis   new bamboo
WebSockets & Ruby EventMachine




(Ruby) WebSockets server


                    • Speak WebSockets (handshake)
                    • Keep connections alive
                    • Performant!
                    • Scalable
                    • Threads? Evented?


                                           Ismael Celis   new bamboo
WebSockets & Ruby EventMachine




EventMachine                     rubyeventmachine.com




                                           Ismael Celis   new bamboo
WebSockets & Ruby EventMachine




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




                                    Ismael Celis   new bamboo
WebSockets & Ruby EventMachine




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




                                    Ismael Celis   new bamboo
WebSockets & Ruby EventMachine



Multiuser




                                 Ismael Celis   new bamboo
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
WebSockets & Ruby EventMachine




Custom JSON format

  [
          “user_connected”,               Event name
            {
                “name” : “Ismael”,
                “message” : “hello!”,    Custom data
                “total_users” : 10
            }

  ]
                                        Ismael Celis   new bamboo
WebSockets & Ruby EventMachine




Javascript wrapper




                                 Ismael Celis   new bamboo
WebSockets & Ruby EventMachine




Javascript wrapper




                                 [ “user_message”,
                                     {
                                         “name” : “Ismael”,
                                         “message” : “hello!”
                                     }

                                 ]
                                                           Ismael Celis   new bamboo
WebSockets & Ruby EventMachine



Implementation                   gist.github.com/299789




                                             Ismael Celis   new bamboo
WebSockets & Ruby EventMachine



Implementation                   gist.github.com/299789




                                             Ismael Celis   new bamboo
WebSockets & Ruby EventMachine



Implementation                   gist.github.com/299789


                                         WebSocket




                                             Ismael Celis   new bamboo
WebSockets & Ruby EventMachine



Implementation                   gist.github.com/299789




                                             Ismael Celis   new bamboo
WebSockets & Ruby EventMachine




           blog.new-bamboo.co.uk



                                 Ismael Celis   new bamboo

More Related Content

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Recently uploaded (20)

Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 

Featured

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Websockets and Ruby EventMachine

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

Editor's Notes

  1. - WebSockets is a HTML5 standard for server-browser persistent connections - Bidirectional - Less overhead than polling and long-polling
  2. - callbacks
  3. - Browser sends &amp;#x201C;Upgrade&amp;#x201D; request. - Server &amp;#x201C;upgrades&amp;#x201D; connection to persistent TCP socket. - No more headers sent.
  4. - &amp;#x201C;messages&amp;#x201D; delimited by these hex characters (null and termination) - incoming message triggers &amp;#x201C;onmessage&amp;#x201D;. - &amp;#x201C;send&amp;#x201D; method wraps messages internally
  5. - listent - send
  6. - Server requirements - Threads: memory bloat
  7. - EventMachine: evented, non-blocking Network connections - predefined callbacks: post_init, receive_data - implement servers (HTTP, WebSockets, others)
  8. - EM-WebSocket extension by Ilya Grigorik - Implements WS server, handshake - WS API callbacks open, message, close
  9. - Send messages back to clients
  10. - store new connections - send message to each connection
  11. - you can structure you messages however you want. - pick the right protocol for your domain - or design your own
  12. - custom JSON format: [event, custom_data] - simple standard for client-side events
  13. - structured JSON messages allow neat JS client. - Browser binds to custom events and manipulates DOM - Treat server as any DOM element
  14. - Send form to sockets server - Familar Javascript events-centric semantics - Wrapper sends JSON event convention
  15. - Simplified. Trivial - wraps WebSocket object - callbacks chain - JSON encoding - decoding
  16. - callback chain - add one or more handlers to each event name
  17. - hook in WebSocket.onmessage() - JSON-decode - execute callbacks for each event name
  18. Trigger and send event to server - JSON-encode message to format convention - [event_name, data]