SlideShare a Scribd company logo
1 of 15
Download to read offline
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!

More Related Content

What's hot

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)Dylan Jay
 
LvivPy - Flask in details
LvivPy - Flask in detailsLvivPy - Flask in details
LvivPy - Flask in detailsMax Klymyshyn
 
Using Websockets with Play!
Using Websockets with Play!Using Websockets with Play!
Using Websockets with Play!Andrew Conner
 
Pyramid Lighter/Faster/Better web apps
Pyramid Lighter/Faster/Better web appsPyramid Lighter/Faster/Better web apps
Pyramid Lighter/Faster/Better web appsDylan Jay
 
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...Edureka!
 
Caching & validating
Caching & validatingCaching & validating
Caching & validatingSon Nguyen
 
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 scalableGareth Marland
 
Build website in_django
Build website in_django Build website in_django
Build website in_django swee meng ng
 
Using Websockets in Play !
Using Websockets in Play !Using Websockets in Play !
Using Websockets in Play !Knoldus Inc.
 
Quick flask an intro to flask
Quick flask   an intro to flaskQuick flask   an intro to flask
Quick flask an intro to flaskjuzten
 
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 jQueryTatsuhiko Miyagawa
 
Ruby HTTP clients comparison
Ruby HTTP clients comparisonRuby HTTP clients comparison
Ruby HTTP clients comparisonHiroshi Nakamura
 
Compress and decompress
Compress and decompressCompress and decompress
Compress and decompressSon Nguyen
 
Symfony2 Components - The Event Dispatcher
Symfony2 Components - The Event DispatcherSymfony2 Components - The Event Dispatcher
Symfony2 Components - The Event DispatcherSarah El-Atm
 
Service Oriented Integration With ServiceMix
Service Oriented Integration With ServiceMixService Oriented Integration With ServiceMix
Service Oriented Integration With ServiceMixBruce Snyder
 

What's hot (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
 

Similar to Real time web_apps_pycon2012-v1

Web application & proxy server
Web application & proxy serverWeb application & proxy server
Web application & proxy serverMeera Hapaliya
 
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 PushDoris 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 codeMatthew Chang
 
video conference (peer to peer)
video conference (peer to peer)video conference (peer to peer)
video conference (peer to peer)mohamed amr
 
Transparent proxy - SIP - 2014 - NCC LAB
Transparent proxy - SIP - 2014 - NCC LABTransparent proxy - SIP - 2014 - NCC LAB
Transparent proxy - SIP - 2014 - NCC LABBenith T
 
Node Session - 1
Node Session - 1Node Session - 1
Node Session - 1Bhavin Shah
 
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 DevelopersViktor Gamov
 
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.jsNicholas Jansma
 
Building Applications With the MEAN Stack
Building Applications With the MEAN StackBuilding Applications With the MEAN Stack
Building Applications With the MEAN StackNir Noy
 
RTP Bluemix Meetup April 20th 2016
RTP Bluemix Meetup April 20th 2016RTP Bluemix Meetup April 20th 2016
RTP Bluemix Meetup April 20th 2016Tom Boucher
 
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 CasesTien Nguyen
 

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

Recently uploaded

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...DianaGray10
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
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 educationjfdjdjcjdnsjd
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
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 WorkerThousandEyes
 
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
 
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
 
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.pdfsudhanshuwaghmare1
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
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
 

Recently uploaded (20)

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...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
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
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
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
 
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
 
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
 
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
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
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
 

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