Your SlideShare is downloading. ×
0
Comet web applications with Python, Django & Orbited
Comet web applications with Python, Django & Orbited
Comet web applications with Python, Django & Orbited
Comet web applications with Python, Django & Orbited
Comet web applications with Python, Django & Orbited
Comet web applications with Python, Django & Orbited
Comet web applications with Python, Django & Orbited
Comet web applications with Python, Django & Orbited
Comet web applications with Python, Django & Orbited
Comet web applications with Python, Django & Orbited
Comet web applications with Python, Django & Orbited
Comet web applications with Python, Django & Orbited
Comet web applications with Python, Django & Orbited
Comet web applications with Python, Django & Orbited
Comet web applications with Python, Django & Orbited
Comet web applications with Python, Django & Orbited
Comet web applications with Python, Django & Orbited
Comet web applications with Python, Django & Orbited
Comet web applications with Python, Django & Orbited
Comet web applications with Python, Django & Orbited
Comet web applications with Python, Django & Orbited
Comet web applications with Python, Django & Orbited
Comet web applications with Python, Django & Orbited
Comet web applications with Python, Django & Orbited
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Comet web applications with Python, Django & Orbited

4,731

Published on

My own talk @ PyCon Italia 4 …

My own talk @ PyCon Italia 4

Developing "realtime" web applications it has never been so easy thanks to Orbited, an implementation of the "Comet" development model written in Python and Javascript.

The first part of the talk will introduce the argument showing all sort of different techniques, highliting all merits and defects and prove how Orbited could be used successfully in this field.

In the second part it will be showed the implementation of an application developed with Django web framework, that could be tried directly by the public.

Published in: Technology
1 Comment
14 Likes
Statistics
Notes
  • do you have demo about this?
    please send it to me?
    thank you!
    my gmail: nhxyj111@gmail.com
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total Views
4,731
On Slideshare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
104
Comments
1
Likes
14
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Comet web applications with Python, Django & Orbited @ PyCon Italia Qu4ttro http://www.pycon.it/ Massimo Scamarcia http://www.webright.it /
  • 2. Comet web applications with Python, Django & Orbited
    • How to push real-time data to web browsers?
  • 3. Comet web applications with Python, Django & Orbited AJAX Polling
    • Client: sends AJAX request.
    • 4. Server:
      • Data available: sends response.
      • 5. No data: sends empty response.
    • Client: sends AJAX request again.
  • 6. Comet web applications with Python, Django & Orbited Latency, bandwidth, memory usage and scaling issues!
  • 7. Comet web applications with Python, Django & Orbited
    • What about Comet?
  • 8. Comet web applications with Python, Django & Orbited
    • Not a technology in itself
    • 9. Long Polling, IFRAME stream, HTMLFile, XHR Streaming, HTML5 SSE
  • 10. Comet web applications with Python, Django & Orbited
    • It's an hack!
    • 11. Still waiting for an unanimous way to do it.
  • 12. Comet web applications with Python, Django & Orbited Long Polling
    • Client: sends AJAX request.
    • 13. Server: holds the request.
      • Data available: sends response.
      • 14. Timeout reached: empty response.
    • Client: sends AJAX request again.
  • 15. Comet web applications with Python, Django & Orbited Http Push (HTTP Streaming*)
    • Client: sends HTTP request.
    • 16. Server: doesn't terminate the connection.
    • 17. Server: sends data when available.
    • 18. Connection closed:
      • Data is queued.
      • 19. Client reconnects.
    [*] http://ajaxpatterns.org/HTTP_Streaming
  • 20. Comet web applications with Python, Django & Orbited
    • HTTP Push: better for heavily-loaded apps.
      • Not cross-browser.
    • Long Polling: cross-browser and easy.
      • Bandwidth usage.
      • 21. Too many connections.
    • Async Python servers* are better for both:
      • Twisted, Tornado, Dieselweb, Eventlet, Concurrence, Circuits, Gevent, Cogen.
    [*] http://nichol.as/asynchronous-servers-in-python
  • 22. Comet web applications with Python, Django & Orbited
    • What about Orbited?
  • 23. Comet web applications with Python, Django & Orbited He's here to solve problems!
  • 24. Comet web applications with Python, Django & Orbited
    • Based on Twisted.
    • 25. STOMP* (ActiveMQ, RabbitMQ), IRC and XMPP protocol support.
    • 26. Ready-to-use and cross-browser JavaScript client code.
    • 27. You don't have to reinvent the wheel!
    [*] http://stomp.codehaus.org/
  • 28. Comet web applications with Python, Django & Orbited
    • Using Django and Orbited Example app developed for PyConIt4: http://pyconquiz.webright.it/
  • 29. Comet web applications with Python, Django & Orbited Django is used for:
    • Application logic.
    • 30. Template rendering.
    • 31. User auth and registration.
    • 32. Handling AJAX requests.
    • 33. Sending messages to STOMP server.
    ...Orbited and jQuery do the rest!
  • 34. Comet web applications with Python, Django & Orbited
  • 35. Comet web applications with Python, Django & Orbited orbited.cfg [global] #reactor=select #reactor=kqueue reactor = epoll proxy.enabled = 1 session.ping_interval = 300 [listen] http://localhost:8080 stomp://localhost:61613 [access] * -> localhost:61613 settings.py # Available using context # processor or templatetag ORBITED_HOST = 'localhost' ORBITED_PORT = 8080 STOMP_HOST = 'localhost' STOMP_PORT = 61613
  • 36. Comet web applications with Python, Django & Orbited Django base template (<head /> tag) <script>document.domain = document.domain;</script> <script src=&quot;{{ ORBITED_MEDIA_URL }}Orbited.js&quot;></script> <script type=&quot;text/javascript&quot;> Orbited.settings.port = {{ ORBITED_PORT }}; Orbited.settings.hostname = &quot;{{ ORBITED_HOST }}&quot;; Orbited.settings.streaming = true; TCPSocket = Orbited.TCPSocket; </script> <script src=&quot;{{ ORBITED_MEDIA_URL }} JSON.js&quot;></script> <script src=&quot;{{ ORBITED_MEDIA_URL }} protocols/stomp/stomp.js&quot;></script>
  • 37. Comet web applications with Python, Django & Orbited <script> $(document).ready(function() { stomp = new STOMPClient(); stomp.onopen = function() { debug('Connected.');}; stomp.onclose = function(c) { debug(Lost Connection, Code: '+c);}; stomp.onerror = function(error){ debug(&quot;Error: &quot; + error);}; stomp.onerrorframe = function(frame){ debug(&quot;Error: &quot; + frame.body);}; stomp.onconnectedframe = function() { {% if game %} stomp.subscribe('/games/{{ game.id }}/status'); stomp.subscribe('/games/{{ game.id }}/players'); {% else %}// subscribe to other channels...{% endif %} }; stomp.onmessageframe = function(frame){ // frame.headers.destination for channel, frame.body for JSON data destpatterns.dispatch(frame); }; stomp.connect('{{ STOMP_HOST }}', {{ STOMP_PORT }}); }); </script>
  • 38. Comet web applications with Python, Django & Orbited Django view @require_POST @login_required def game_start(request, game_id): game = get_object_or_404(Game, id=game_id) if request.user != game.author: return HttpResponseForbidden() try: # start() method set game start_time and send JSON # to ”/games/{{ game.id }}/status” using stomp.py game.start() except GameError, e: return JSONResponse({'error': str(e)}) return JSONResponse({})
  • 39. Comet web applications with Python, Django & Orbited
    • Does it scale?
  • 40. Comet web applications with Python, Django & Orbited
  • 41. Comet web applications with Python, Django & Orbited
  • 42. Comet web applications with Python, Django & Orbited
    • Thank you and have fun with the quiz game!

×