SlideShare ist ein Scribd-Unternehmen logo
1 von 15
Downloaden Sie, um offline zu lesen
Real Time Django Applications




        Avinash Prasad
         Python developer

         Xoriant Solutions
Great
                 &   =   Web
                         Apps


Avinash Prasad              09/29/2012
A real time application:
     ●   Accesses real-time near real-time data

     ●   Connectivity via full duplex network connections

     ●   Capable of pushing data to the client at anytime


     A web application:
     ● Started as a static content delivery mechanism over a stateless
     request and response architecture of HTTP.

     ● Emergence of technologies like AJAX, Servlets brought a revelation
     in the web application development making it dynamic(aka RIA)



Avinash Prasad                                                           09/29/2012
What next ?


       ●
           Lets bring some life to our web application

       ●   Make it faster

       ●   Enhance the user experience

                                              But before that....




Avinash Prasad                                                 09/29/2012
Techniques used to make Rich Internet
   Applications
   Polling
   ●Easiest way to retrieve the latest data and events from the server for a
   Web application.


   ●The Web application essentially polls the server on a regular basis,
   based on a timer.


   ● The timeliness of the data is directly proportional to the polling
   frequency.


   ●   Uses a simple HTTP request each time the timer expires.


Avinash Prasad                                                            09/29/2012
Techniques used to make Rich Internet
   Applications

   Asynchronous Polling
   ● In asynchronous polling the browser sends a request to the server and
   the server keeps the request open for a set period.


   ●If a notification is received within that period, a response containing the
   message is sent to the client.


   ● If a notification is not received within the set time period, the server
   sends a response to terminate the open request and the browser resends
   the request to the server.


Avinash Prasad                                                            09/29/2012
Techniques used to make Rich Internet
   Applications
   Streaming
   ●When streaming is used, the browser sends a complete request, but the
   server sends and maintains an open response that is continuously
   updated.


   ● A request is sent and kept open indefinitely (or for a set period of time)
   and the response is updated whenever a message is ready to be sent, but
   the server never signals to complete the response


   ●   Thereby keeping the connection open to deliver future messages.




Avinash Prasad                                                           09/29/2012
Lets bring in some awesomeness.....



                 Web Sockets

    The WebSocket Interface defines a full duplex communications channel that is
    exposed via a JavaScript interface in HTML 5 compliant browsers.


    What web sockets can do for you ?
    ●Persistent connection between the client and the server enabling both
    parties to send data at any time.

    ● Reduces the overhead of HTTP, thereby making them well suited for low
    latency applications



Avinash Prasad                                                               09/29/2012
Web Sockets

       A web socket can be opened by calling the WebSocket constructor:
            var connection = new WebSocket('ws://localhost:8005/chat',
                                [subprotocols..]);

       ws: new URL schema for WebSocket connections. Also an option for wss exists, socket over
       HTTPS

       Communicating with the server
       // When the connection is open, send some data to the server

       connection.onopen = function () {

       connection.send('Ping'); // Send the message 'Ping' to the server



       connection.onerror = function (error) {

        console.log('WebSocket Error ' + error); // Log errors

       };

       connection.onmessage = function (e) {

            console.log('Server: ' + e.data); // Log messages from the server

       };

Avinash Prasad                                                                            09/29/2012
django to the rescue

                 Django can be used as the sever side component along with HTML5
                 WebSockets.
                 An implementation called django-socketIO can be particularly used
                 to build real time applications.

                 Django-socketio is a BSD licensed django application that brings
                 together a variety of features that allow you to use websockets
                 seamlessly with any django project.

                 Built after taking inspiration from applications built using Socket.IO
                 and gevent with django.




Avinash Prasad                                                                 09/29/2012
Django-socketio
                 Features
                 ●A management command for running gevent's pywsgi server with
                 auto-reloading capabilities

                 ●A channel subscription and broadcast system that extends
                 Socket.IO allowing WebSockets and events to be partitioned into
                 separate concerns

                 ●A signals-like event system that abstracts away the various stages
                 of a Socket.IO request




Avinash Prasad                                                                09/29/2012
Django-socketio
                 Components
                 ●   Channels

                 ●   Broadcast mechanism

                 ●   Events
   Channels: A common requirement in websocket based communication are multiple
   channels so that communication can be divided effectively .
   django-socketio extends Socket.IO both on the client and server to provide channels
   that can be subscribed and broadcast to.

   At JavaScript end we can use,

   var socket = new io.Socket();
   socket.connect();
   socket.on('connect', function() {
        socket.subscribe('my channel');
   });
   Once the socket is subscribed to a channel, broadcast to the channel server-side is
   done at Python using the socket.broadcast_channel method:
Avinash Prasad                                                                       09/29/2012
Broadcast Mechanism: Each server-side socket has the following methods,

   ●   django_socketio.broadcast(message)

   ●   django_socketio.broadcast_channel(message, channel)

   ●   django_socketio.send(session_id, message)

       Note:
       In send method, the socket is identified by its session ID, accessible
       via socket.session.session_id. Its web-socket's session id and not
       Django's session id.

   Events: The django_socketio.events module is quiet similar to Django's
   signaling module and has events similar to Django's signals.

   They are raised at any stage during a websocket request.

   Each of the event enables us to implement our own socket handling logic
   using its session id.



Avinash Prasad                                                                  09/29/2012
Demo application(s) with brief description
      on implementation details
Thank You!

Weitere ähnliche Inhalte

Was ist angesagt?

Websockets in Node.js - Making them reliable and scalable
Websockets in Node.js - Making them reliable and scalableWebsockets in Node.js - Making them reliable and scalable
Websockets in Node.js - Making them reliable and scalable
Gareth Marland
 
Build website in_django
Build website in_django Build website in_django
Build website in_django
swee meng ng
 
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQueryRemedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Tatsuhiko Miyagawa
 
Ruby HTTP clients comparison
Ruby HTTP clients comparisonRuby HTTP clients comparison
Ruby HTTP clients comparison
Hiroshi Nakamura
 
Symfony2 Components - The Event Dispatcher
Symfony2 Components - The Event DispatcherSymfony2 Components - The Event Dispatcher
Symfony2 Components - The Event Dispatcher
Sarah El-Atm
 

Was ist angesagt? (20)

The goodies of zope, pyramid, and plone (2)
The goodies of zope, pyramid, and plone (2)The goodies of zope, pyramid, and plone (2)
The goodies of zope, pyramid, and plone (2)
 
Writing Pluggable Software
Writing Pluggable SoftwareWriting Pluggable Software
Writing Pluggable Software
 
LvivPy - Flask in details
LvivPy - Flask in detailsLvivPy - Flask in details
LvivPy - Flask in details
 
The HTML5 WebSocket API
The HTML5 WebSocket APIThe HTML5 WebSocket API
The HTML5 WebSocket API
 
Using Websockets with Play!
Using Websockets with Play!Using Websockets with Play!
Using Websockets with Play!
 
Pyramid Lighter/Faster/Better web apps
Pyramid Lighter/Faster/Better web appsPyramid Lighter/Faster/Better web apps
Pyramid Lighter/Faster/Better web apps
 
Python Flask Tutorial For Beginners | Flask Web Development Tutorial | Python...
Python Flask Tutorial For Beginners | Flask Web Development Tutorial | Python...Python Flask Tutorial For Beginners | Flask Web Development Tutorial | Python...
Python Flask Tutorial For Beginners | Flask Web Development Tutorial | Python...
 
Caching & validating
Caching & validatingCaching & validating
Caching & validating
 
Develop webservice in PHP
Develop webservice in PHPDevelop webservice in PHP
Develop webservice in PHP
 
Websockets in Node.js - Making them reliable and scalable
Websockets in Node.js - Making them reliable and scalableWebsockets in Node.js - Making them reliable and scalable
Websockets in Node.js - Making them reliable and scalable
 
Build website in_django
Build website in_django Build website in_django
Build website in_django
 
Plack - LPW 2009
Plack - LPW 2009Plack - LPW 2009
Plack - LPW 2009
 
Tatsumaki
TatsumakiTatsumaki
Tatsumaki
 
Using Websockets in Play !
Using Websockets in Play !Using Websockets in Play !
Using Websockets in Play !
 
Quick flask an intro to flask
Quick flask   an intro to flaskQuick flask   an intro to flask
Quick flask an intro to flask
 
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQueryRemedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
 
Ruby HTTP clients comparison
Ruby HTTP clients comparisonRuby HTTP clients comparison
Ruby HTTP clients comparison
 
Compress and decompress
Compress and decompressCompress and decompress
Compress and decompress
 
Symfony2 Components - The Event Dispatcher
Symfony2 Components - The Event DispatcherSymfony2 Components - The Event Dispatcher
Symfony2 Components - The Event Dispatcher
 
Service Oriented Integration With ServiceMix
Service Oriented Integration With ServiceMixService Oriented Integration With ServiceMix
Service Oriented Integration With ServiceMix
 

Ähnlich wie Real time web_apps_pycon2012-v1

Real time Communication with Signalr (Android Client)
Real time Communication with Signalr (Android Client)Real time Communication with Signalr (Android Client)
Real time Communication with Signalr (Android Client)
Deepak Gupta
 
Developing Revolutionary Web Applications using Comet and Ajax Push
Developing Revolutionary Web Applications using Comet and Ajax PushDeveloping Revolutionary Web Applications using Comet and Ajax Push
Developing Revolutionary Web Applications using Comet and Ajax Push
Doris Chen
 
A new interface between smart device and web using html5 web socket and qr code
A new interface between smart device and web using html5 web socket and qr codeA new interface between smart device and web using html5 web socket and qr code
A new interface between smart device and web using html5 web socket and qr code
Matthew Chang
 
Transparent proxy - SIP - 2014 - NCC LAB
Transparent proxy - SIP - 2014 - NCC LABTransparent proxy - SIP - 2014 - NCC LAB
Transparent proxy - SIP - 2014 - NCC LAB
Benith T
 
WebSockets: The Current State of the Most Valuable HTML5 API for Java Developers
WebSockets: The Current State of the Most Valuable HTML5 API for Java DevelopersWebSockets: The Current State of the Most Valuable HTML5 API for Java Developers
WebSockets: The Current State of the Most Valuable HTML5 API for Java Developers
Viktor Gamov
 

Ähnlich wie Real time web_apps_pycon2012-v1 (20)

ServerSentEventsV2.pdf
ServerSentEventsV2.pdfServerSentEventsV2.pdf
ServerSentEventsV2.pdf
 
Web application & proxy server
Web application & proxy serverWeb application & proxy server
Web application & proxy server
 
Real time Communication with Signalr (Android Client)
Real time Communication with Signalr (Android Client)Real time Communication with Signalr (Android Client)
Real time Communication with Signalr (Android Client)
 
Developing Revolutionary Web Applications using Comet and Ajax Push
Developing Revolutionary Web Applications using Comet and Ajax PushDeveloping Revolutionary Web Applications using Comet and Ajax Push
Developing Revolutionary Web Applications using Comet and Ajax Push
 
A new interface between smart device and web using html5 web socket and qr code
A new interface between smart device and web using html5 web socket and qr codeA new interface between smart device and web using html5 web socket and qr code
A new interface between smart device and web using html5 web socket and qr code
 
Websockets and SockJS, Real time chatting
Websockets and SockJS, Real time chattingWebsockets and SockJS, Real time chatting
Websockets and SockJS, Real time chatting
 
Signal R 2015
Signal R 2015Signal R 2015
Signal R 2015
 
video conference (peer to peer)
video conference (peer to peer)video conference (peer to peer)
video conference (peer to peer)
 
zigbee
zigbeezigbee
zigbee
 
Transparent proxy - SIP - 2014 - NCC LAB
Transparent proxy - SIP - 2014 - NCC LABTransparent proxy - SIP - 2014 - NCC LAB
Transparent proxy - SIP - 2014 - NCC LAB
 
Node Session - 1
Node Session - 1Node Session - 1
Node Session - 1
 
WebSockets: The Current State of the Most Valuable HTML5 API for Java Developers
WebSockets: The Current State of the Most Valuable HTML5 API for Java DevelopersWebSockets: The Current State of the Most Valuable HTML5 API for Java Developers
WebSockets: The Current State of the Most Valuable HTML5 API for Java Developers
 
The Happy Path: Migration Strategies for Node.js
The Happy Path: Migration Strategies for Node.jsThe Happy Path: Migration Strategies for Node.js
The Happy Path: Migration Strategies for Node.js
 
Web Performance Optimization
Web Performance OptimizationWeb Performance Optimization
Web Performance Optimization
 
Node js - Yns
Node js - YnsNode js - Yns
Node js - Yns
 
Building Applications With the MEAN Stack
Building Applications With the MEAN StackBuilding Applications With the MEAN Stack
Building Applications With the MEAN Stack
 
IoT-javascript-2019-fosdem
IoT-javascript-2019-fosdemIoT-javascript-2019-fosdem
IoT-javascript-2019-fosdem
 
RTP Bluemix Meetup April 20th 2016
RTP Bluemix Meetup April 20th 2016RTP Bluemix Meetup April 20th 2016
RTP Bluemix Meetup April 20th 2016
 
An In-Depth Comparison of WebSocket and SignalR: Pros, Cons, and Use Cases
An In-Depth Comparison of WebSocket and SignalR: Pros, Cons, and Use CasesAn In-Depth Comparison of WebSocket and SignalR: Pros, Cons, and Use Cases
An In-Depth Comparison of WebSocket and SignalR: Pros, Cons, and Use Cases
 
WebRTC Seminar Report
WebRTC  Seminar ReportWebRTC  Seminar Report
WebRTC Seminar Report
 

Kürzlich hochgeladen

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

Kürzlich hochgeladen (20)

Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
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...
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
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...
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
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)
 
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
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
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
 
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
 
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
 
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
 
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
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
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
 
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
 
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
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 

Real time web_apps_pycon2012-v1

  • 1. Real Time Django Applications Avinash Prasad Python developer Xoriant Solutions
  • 2. Great & = Web Apps Avinash Prasad 09/29/2012
  • 3. A real time application: ● Accesses real-time near real-time data ● Connectivity via full duplex network connections ● Capable of pushing data to the client at anytime A web application: ● Started as a static content delivery mechanism over a stateless request and response architecture of HTTP. ● Emergence of technologies like AJAX, Servlets brought a revelation in the web application development making it dynamic(aka RIA) Avinash Prasad 09/29/2012
  • 4. What next ? ● Lets bring some life to our web application ● Make it faster ● Enhance the user experience But before that.... Avinash Prasad 09/29/2012
  • 5. Techniques used to make Rich Internet Applications Polling ●Easiest way to retrieve the latest data and events from the server for a Web application. ●The Web application essentially polls the server on a regular basis, based on a timer. ● The timeliness of the data is directly proportional to the polling frequency. ● Uses a simple HTTP request each time the timer expires. Avinash Prasad 09/29/2012
  • 6. Techniques used to make Rich Internet Applications Asynchronous Polling ● In asynchronous polling the browser sends a request to the server and the server keeps the request open for a set period. ●If a notification is received within that period, a response containing the message is sent to the client. ● If a notification is not received within the set time period, the server sends a response to terminate the open request and the browser resends the request to the server. Avinash Prasad 09/29/2012
  • 7. Techniques used to make Rich Internet Applications Streaming ●When streaming is used, the browser sends a complete request, but the server sends and maintains an open response that is continuously updated. ● A request is sent and kept open indefinitely (or for a set period of time) and the response is updated whenever a message is ready to be sent, but the server never signals to complete the response ● Thereby keeping the connection open to deliver future messages. Avinash Prasad 09/29/2012
  • 8. Lets bring in some awesomeness..... Web Sockets The WebSocket Interface defines a full duplex communications channel that is exposed via a JavaScript interface in HTML 5 compliant browsers. What web sockets can do for you ? ●Persistent connection between the client and the server enabling both parties to send data at any time. ● Reduces the overhead of HTTP, thereby making them well suited for low latency applications Avinash Prasad 09/29/2012
  • 9. Web Sockets A web socket can be opened by calling the WebSocket constructor: var connection = new WebSocket('ws://localhost:8005/chat', [subprotocols..]); ws: new URL schema for WebSocket connections. Also an option for wss exists, socket over HTTPS Communicating with the server // When the connection is open, send some data to the server connection.onopen = function () { connection.send('Ping'); // Send the message 'Ping' to the server connection.onerror = function (error) { console.log('WebSocket Error ' + error); // Log errors }; connection.onmessage = function (e) { console.log('Server: ' + e.data); // Log messages from the server }; Avinash Prasad 09/29/2012
  • 10. django to the rescue Django can be used as the sever side component along with HTML5 WebSockets. An implementation called django-socketIO can be particularly used to build real time applications. Django-socketio is a BSD licensed django application that brings together a variety of features that allow you to use websockets seamlessly with any django project. Built after taking inspiration from applications built using Socket.IO and gevent with django. Avinash Prasad 09/29/2012
  • 11. Django-socketio Features ●A management command for running gevent's pywsgi server with auto-reloading capabilities ●A channel subscription and broadcast system that extends Socket.IO allowing WebSockets and events to be partitioned into separate concerns ●A signals-like event system that abstracts away the various stages of a Socket.IO request Avinash Prasad 09/29/2012
  • 12. Django-socketio Components ● Channels ● Broadcast mechanism ● Events Channels: A common requirement in websocket based communication are multiple channels so that communication can be divided effectively . django-socketio extends Socket.IO both on the client and server to provide channels that can be subscribed and broadcast to. At JavaScript end we can use, var socket = new io.Socket(); socket.connect(); socket.on('connect', function() { socket.subscribe('my channel'); }); Once the socket is subscribed to a channel, broadcast to the channel server-side is done at Python using the socket.broadcast_channel method: Avinash Prasad 09/29/2012
  • 13. Broadcast Mechanism: Each server-side socket has the following methods, ● django_socketio.broadcast(message) ● django_socketio.broadcast_channel(message, channel) ● django_socketio.send(session_id, message) Note: In send method, the socket is identified by its session ID, accessible via socket.session.session_id. Its web-socket's session id and not Django's session id. Events: The django_socketio.events module is quiet similar to Django's signaling module and has events similar to Django's signals. They are raised at any stage during a websocket request. Each of the event enables us to implement our own socket handling logic using its session id. Avinash Prasad 09/29/2012
  • 14. Demo application(s) with brief description on implementation details