SlideShare a Scribd company logo
1 of 36
Download to read offline
Realtime Web with PocketIO
    Ynon Perek

    Tel Aviv Perl Mongers


Saturday, November 24, 12
Whoami



    ✤    Ynon Perek

    ✤    ynonperek.com

    ✤    me@ynonperek.com




Saturday, November 24, 12
Agenda



    ✤    What’s wrong with HTTP

    ✤    Real Time Web - Concepts

    ✤    PocketIO Coding Demos




Saturday, November 24, 12
What is wrong with HTTP ?



                            GET page




                            Here It Is




Saturday, November 24, 12
Let’s try a Live Chat




Saturday, November 24, 12
HTTP Live Chat

    ✤    All communication is mediated by server using HTTP


                              Tell Laura I Love Her




Saturday, November 24, 12
HTTP Live Chat

    ✤    But the server can only reply ...


                                        Ok, got it




Saturday, November 24, 12
HTTP Live Chat

    ✤    Waiting...




Saturday, November 24, 12
HTTP Live Chat

    ✤    Meantime, on Laura’s side


                                 Do I have any
                                  messages ?



                                Tommy said he
                                  loves you




Saturday, November 24, 12
A second later




Saturday, November 24, 12
HTTP Live Chat



                            Do I have any new
                               messages ?



                               No, sorry




Saturday, November 24, 12
A second later




Saturday, November 24, 12
HTTP Live Chat



                            Do I have any new
                               messages ?



                               No, sorry




Saturday, November 24, 12
A second later




Saturday, November 24, 12
HTTP Live Chat



                            Do I have any new
                               messages ?



                               No, sorry




Saturday, November 24, 12
HTTP Live Chat Dark Side



    ✤    Server is busy picking up requests

    ✤    Clients are busy polling

    ✤    Everyone loses




Saturday, November 24, 12
Real Time
    Web



    ✤    Improved UX by allowing the
         server to notify a client




Saturday, November 24, 12
What’s Available



    ✤    Plugins (usually flash) to open client/server sockets

    ✤    Comet

    ✤    Web Sockets (modern browsers)




Saturday, November 24, 12
Meet PocketIO
    Perl implementation of Socket.IO written
    by vti




Saturday, November 24, 12
The Good


    ✤    Chooses the best available
         transport layer

    ✤    Manages active connections
         and reconnections

    ✤    Awesome




Saturday, November 24, 12
Coding Time




Saturday, November 24, 12
What You Need



    ✤    Use Twiggy (or fliggy)

    ✤    Use Plack::Builder




Saturday, November 24, 12
What You Need

    ✤    /socket.io/socket.io.js should point to the client-side library


               mount '/socket.io/socket.io.js' =>
                 Plack::App::File->new(
                      file => "$root/public/javascripts/socket.io.js");




Saturday, November 24, 12
What You Need

    ✤    /socket.io should return a new PocketIO object



             mount '/socket.io' => PocketIO->new(
                 class => 'PocketHandler',
                 method => 'run',
             );




                            Method that returns a subroutine
                            reference to bind socket actions
Saturday, November 24, 12
PocketIO::Run




    ✤    Demo 1: Echo Server




Saturday, November 24, 12
PocketIO Broadcasts

    ✤    notify all except sender:
         $sender->broadcast->emit(‘message’, ‘text’);


    ✤    notify all (including sender)
         $sender->sockets->emit(‘message’, ‘text’);

    ✤    send an object
         $sender->sockets->emit(‘message’, {
            message => ‘text’
         });


Saturday, November 24, 12
PocketIO Broadcasts



    ✤    Demo2: Shared Echo (wall)

    ✤    Let’s turn our wall to multi-user wall




Saturday, November 24, 12
PocketIO Sharing Data



    ✤    Use an external data store (DB, Redis)

    ✤    Use Plack




Saturday, November 24, 12
External Data Store


                                   Shared Data
                                      Store




                        PocketIO                 Dancer




Saturday, November 24, 12
Plack



    ✤    Create a shared variable in Plack::Builder (or a middleware)

    ✤    Pass it to all apps

    ✤    Demo




Saturday, November 24, 12
PocketIO
    Takeaways


    ✤    Bring users closer together by
         allowing smooth collaboration

    ✤    Improve UX

    ✤    Multiplayer Zombie Slaying
         games FTW




Saturday, November 24, 12
Thank You


    ✤    Keynote’s available at:
         http://www.slideshare.net/YnonPerek

    ✤    Code available at:
         https://github.com/ynonp/pm-nov-12

    ✤    Visit me on:
         http://mobileweb.ynonperek.com




Saturday, November 24, 12
RealTime Web with PocketIO
RealTime Web with PocketIO
RealTime Web with PocketIO
RealTime Web with PocketIO

More Related Content

More from Ynon Perek

09 performance
09 performance09 performance
09 performanceYnon Perek
 
Mobile Web Intro
Mobile Web IntroMobile Web Intro
Mobile Web IntroYnon Perek
 
Qt multi threads
Qt multi threadsQt multi threads
Qt multi threadsYnon Perek
 
Mobile Devices
Mobile DevicesMobile Devices
Mobile DevicesYnon Perek
 
Architecture app
Architecture appArchitecture app
Architecture appYnon Perek
 
Unit Testing JavaScript Applications
Unit Testing JavaScript ApplicationsUnit Testing JavaScript Applications
Unit Testing JavaScript ApplicationsYnon Perek
 
How to write easy-to-test JavaScript
How to write easy-to-test JavaScriptHow to write easy-to-test JavaScript
How to write easy-to-test JavaScriptYnon Perek
 
Introduction to Selenium and Ruby
Introduction to Selenium and RubyIntroduction to Selenium and Ruby
Introduction to Selenium and RubyYnon Perek
 
Introduction To Web Application Testing
Introduction To Web Application TestingIntroduction To Web Application Testing
Introduction To Web Application TestingYnon Perek
 
Qt Design Patterns
Qt Design PatternsQt Design Patterns
Qt Design PatternsYnon Perek
 
Web Application Security
Web Application SecurityWeb Application Security
Web Application SecurityYnon Perek
 

More from Ynon Perek (20)

Regexp
RegexpRegexp
Regexp
 
Html5 intro
Html5 introHtml5 intro
Html5 intro
 
09 performance
09 performance09 performance
09 performance
 
Mobile Web Intro
Mobile Web IntroMobile Web Intro
Mobile Web Intro
 
Qt multi threads
Qt multi threadsQt multi threads
Qt multi threads
 
Vimperl
VimperlVimperl
Vimperl
 
Syllabus
SyllabusSyllabus
Syllabus
 
Mobile Devices
Mobile DevicesMobile Devices
Mobile Devices
 
Network
NetworkNetwork
Network
 
Architecture app
Architecture appArchitecture app
Architecture app
 
Cryptography
CryptographyCryptography
Cryptography
 
Unit Testing JavaScript Applications
Unit Testing JavaScript ApplicationsUnit Testing JavaScript Applications
Unit Testing JavaScript Applications
 
How to write easy-to-test JavaScript
How to write easy-to-test JavaScriptHow to write easy-to-test JavaScript
How to write easy-to-test JavaScript
 
Introduction to Selenium and Ruby
Introduction to Selenium and RubyIntroduction to Selenium and Ruby
Introduction to Selenium and Ruby
 
Introduction To Web Application Testing
Introduction To Web Application TestingIntroduction To Web Application Testing
Introduction To Web Application Testing
 
Accessibility
AccessibilityAccessibility
Accessibility
 
Angularjs
AngularjsAngularjs
Angularjs
 
Js memory
Js memoryJs memory
Js memory
 
Qt Design Patterns
Qt Design PatternsQt Design Patterns
Qt Design Patterns
 
Web Application Security
Web Application SecurityWeb Application Security
Web Application Security
 

Recently uploaded

Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 

Recently uploaded (20)

Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 

RealTime Web with PocketIO

  • 1. Realtime Web with PocketIO Ynon Perek Tel Aviv Perl Mongers Saturday, November 24, 12
  • 2. Whoami ✤ Ynon Perek ✤ ynonperek.com ✤ me@ynonperek.com Saturday, November 24, 12
  • 3. Agenda ✤ What’s wrong with HTTP ✤ Real Time Web - Concepts ✤ PocketIO Coding Demos Saturday, November 24, 12
  • 4. What is wrong with HTTP ? GET page Here It Is Saturday, November 24, 12
  • 5. Let’s try a Live Chat Saturday, November 24, 12
  • 6. HTTP Live Chat ✤ All communication is mediated by server using HTTP Tell Laura I Love Her Saturday, November 24, 12
  • 7. HTTP Live Chat ✤ But the server can only reply ... Ok, got it Saturday, November 24, 12
  • 8. HTTP Live Chat ✤ Waiting... Saturday, November 24, 12
  • 9. HTTP Live Chat ✤ Meantime, on Laura’s side Do I have any messages ? Tommy said he loves you Saturday, November 24, 12
  • 10. A second later Saturday, November 24, 12
  • 11. HTTP Live Chat Do I have any new messages ? No, sorry Saturday, November 24, 12
  • 12. A second later Saturday, November 24, 12
  • 13. HTTP Live Chat Do I have any new messages ? No, sorry Saturday, November 24, 12
  • 14. A second later Saturday, November 24, 12
  • 15. HTTP Live Chat Do I have any new messages ? No, sorry Saturday, November 24, 12
  • 16. HTTP Live Chat Dark Side ✤ Server is busy picking up requests ✤ Clients are busy polling ✤ Everyone loses Saturday, November 24, 12
  • 17. Real Time Web ✤ Improved UX by allowing the server to notify a client Saturday, November 24, 12
  • 18. What’s Available ✤ Plugins (usually flash) to open client/server sockets ✤ Comet ✤ Web Sockets (modern browsers) Saturday, November 24, 12
  • 19. Meet PocketIO Perl implementation of Socket.IO written by vti Saturday, November 24, 12
  • 20. The Good ✤ Chooses the best available transport layer ✤ Manages active connections and reconnections ✤ Awesome Saturday, November 24, 12
  • 22. What You Need ✤ Use Twiggy (or fliggy) ✤ Use Plack::Builder Saturday, November 24, 12
  • 23. What You Need ✤ /socket.io/socket.io.js should point to the client-side library mount '/socket.io/socket.io.js' => Plack::App::File->new( file => "$root/public/javascripts/socket.io.js"); Saturday, November 24, 12
  • 24. What You Need ✤ /socket.io should return a new PocketIO object mount '/socket.io' => PocketIO->new( class => 'PocketHandler', method => 'run', ); Method that returns a subroutine reference to bind socket actions Saturday, November 24, 12
  • 25. PocketIO::Run ✤ Demo 1: Echo Server Saturday, November 24, 12
  • 26. PocketIO Broadcasts ✤ notify all except sender: $sender->broadcast->emit(‘message’, ‘text’); ✤ notify all (including sender) $sender->sockets->emit(‘message’, ‘text’); ✤ send an object $sender->sockets->emit(‘message’, { message => ‘text’ }); Saturday, November 24, 12
  • 27. PocketIO Broadcasts ✤ Demo2: Shared Echo (wall) ✤ Let’s turn our wall to multi-user wall Saturday, November 24, 12
  • 28. PocketIO Sharing Data ✤ Use an external data store (DB, Redis) ✤ Use Plack Saturday, November 24, 12
  • 29. External Data Store Shared Data Store PocketIO Dancer Saturday, November 24, 12
  • 30. Plack ✤ Create a shared variable in Plack::Builder (or a middleware) ✤ Pass it to all apps ✤ Demo Saturday, November 24, 12
  • 31. PocketIO Takeaways ✤ Bring users closer together by allowing smooth collaboration ✤ Improve UX ✤ Multiplayer Zombie Slaying games FTW Saturday, November 24, 12
  • 32. Thank You ✤ Keynote’s available at: http://www.slideshare.net/YnonPerek ✤ Code available at: https://github.com/ynonp/pm-nov-12 ✤ Visit me on: http://mobileweb.ynonperek.com Saturday, November 24, 12