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

Mobile Devices
Mobile DevicesMobile Devices
Mobile Devices
Ynon 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

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
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
 
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
 

Recently uploaded (20)

Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
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
 
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
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
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
 
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
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
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
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
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
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
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
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
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, ...
 

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