Successfully reported this slideshow.
Comet implementations for Perl                                    Marian HackMan Marinov                               Co-...
Replacing browser PULL                               with server PUSH       What is Comet?                               A...
Hidden iframe                               XMLHttpRequest                               long polling with                ...
Bulgarian Perl Workshop 2013
Iframe sent as                          Hidden iframe  chunked blcok  Infinitely long                               Works ...
hackman@gamelon:~$ curl http://localhost:4670/push/12345/iframe/channel1<html><head><meta http-equiv="Content-Type" conten...
XMLHttpRequestContent-type: multipart/x-mixed-replace; boundary=NEXTPARTrnrn                               The Ajax way of...
hackman@gamelon:~$ curl http://localhost:8000/--NEXTPARTContent-type: text/plain<script>document.getElementById(counter).i...
Long PollingXMLHttpRequest- creates a request- when all data is received- creates subsequent requestBulgarian Perl Worksho...
Long Polling<script> tag- creates a script tag- when all data is received- creates new script tagBulgarian Perl Workshop 2...
Meteor                               Stardust                               Frameworks:                                - M...
http://meteorserver.org/ Meteor                               Stand alone web server                               Support...
Event controller commands                               ADDMESSAGE chan msg                               COUNTSUBSCRIBERS...
hackman@gamelon:~/Comet$ nc localhost 4671  SHOWSTATS  OK  uptime: 279  channel_count: 0  subscriber_connections_accepted:...
$ curl http://localhost:4670/push/12345/iframe/channel1  <html><head>  <script type="text/javascript">  window.onError = n...
$ curl http://localhost:4670/push/12345/xhrinteractive/channel1..............................................................
$ curl http://localhost:4670/push/12345/simplepoll/channel1<script>ch("channel1", 3);</script>hackman@gamelon:~$$ curl htt...
Stand alone web serverAlmost no documentation                  StardustNo updates since 2011Supports:stream and longpollre...
$ curl -d m={ "type": "Test", "data": [1,2,3] } http://localhost:5742/channel/foo/stream/foo//channel/foo/stream/foo/ not ...
Other Perl comet implementations: - POE-Component-Server-Bayeux - Tatsumaki Additional readings:   http://toroid.org/ams/e...
More on the subject here:          http://www.slideshare.net/simon/time-for-comet         ?                     ?         ...
Upcoming SlideShare
Loading in …5
×

Perl comet

3,168 views

Published on

  • Be the first to comment

Perl comet

  1. 1. Comet implementations for Perl Marian HackMan Marinov Co-founder and CEO of 1H Ltd. mm@1h.comBulgarian Perl Workshop 2013
  2. 2. Replacing browser PULL with server PUSH What is Comet? AJAX Push Reverse AJAX Two-way-web HTTP Streaming HTTP Server PushBulgarian Perl Workshop 2013
  3. 3. Hidden iframe XMLHttpRequest long polling with - AJAX - XMLHttpRequest - Script tag ImplementationsBulgarian Perl Workshop 2013
  4. 4. Bulgarian Perl Workshop 2013
  5. 5. Iframe sent as Hidden iframe chunked blcok Infinitely long Works on every browser Lacks reliable error handling Connection state unavailableBulgarian Perl Workshop 2013
  6. 6. hackman@gamelon:~$ curl http://localhost:4670/push/12345/iframe/channel1<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"<meta http-equiv="Cache-Control" content="no-store"><meta http-equiv="Cache-Control" content="no-cache"><meta http-equiv="Pragma" content="no-cache"><meta http-equiv="Expires" content="Thu, 1 Jan 1970 00:00:00 GMT"></head><body><script>document.getElementById(counter).innerHTML = 1;</script><script>document.getElementById(counter).innerHTML = 2;</script><script>document.getElementById(counter).innerHTML = 3;</script><script>document.getElementById(counter).innerHTML = 4;</script><script>document.getElementById(counter).innerHTML = 5;</script><script>document.getElementById(counter).innerHTML = 6;</script><html><head><title>Comet test Page</title></head><body><h2 align="center">My counter: </h2> <span id=counter></span><iframe href=http://localhost:8000 height=0 width=0></iframe></body></html>Bulgarian Perl Workshop 2013
  7. 7. XMLHttpRequestContent-type: multipart/x-mixed-replace; boundary=NEXTPARTrnrn The Ajax way of using Comet Reliable connection handling Connection state informationBulgarian Perl Workshop 2013
  8. 8. hackman@gamelon:~$ curl http://localhost:8000/--NEXTPARTContent-type: text/plain<script>document.getElementById(counter).innerHTML = 0;</script>--NEXTPARTContent-type: text/plain<script>document.getElementById(counter).innerHTML = 1;</script>--NEXTPARTContent-type: text/plain<script>document.getElementById(counter).innerHTML = 2;</script>--NEXTPARTBulgarian Perl Workshop 2013
  9. 9. Long PollingXMLHttpRequest- creates a request- when all data is received- creates subsequent requestBulgarian Perl Workshop 2013
  10. 10. Long Polling<script> tag- creates a script tag- when all data is received- creates new script tagBulgarian Perl Workshop 2013
  11. 11. Meteor Stardust Frameworks: - Mojolicious - PSGI - ContinuityWhat Comet implementationswe have in PerlBulgarian Perl Workshop 2013
  12. 12. http://meteorserver.org/ Meteor Stand alone web server Supports: - iframe - xhrinteractive - simplepoll & smartpoll - longpoll - flash & flashloadvarsBulgarian Perl Workshop 2013
  13. 13. Event controller commands ADDMESSAGE chan msg COUNTSUBSCRIBERS chan LISTCHANNELS SHOWSTATS QUITBulgarian Perl Workshop 2013
  14. 14. hackman@gamelon:~/Comet$ nc localhost 4671 SHOWSTATS OK uptime: 279 channel_count: 0 subscriber_connections_accepted: 3 controller_connections_accepted: 1 total_inbound_bytes: 524 total_outbound_bytes: 646 documents_not_found: 3 current_controllers: 1 total_requests: 4 current_subscribers: 0 --EOT-- ADDMESSAGE channel1 testing OK 0 LISTCHANNELS OK channel1(1/0) --EOT-- ADDMESSAGE channel1 dddddd OK 1Bulgarian Perl Workshop 2013
  15. 15. $ curl http://localhost:4670/push/12345/iframe/channel1 <html><head> <script type="text/javascript"> window.onError = null; var domainparts = document.domain.split("."); document.domain = domainparts[domainparts.length-2]+". "+domainparts[domainparts.length-1]; parent.Meteor.register(this); </script> </head> <body onload="try { parent.Meteor.reset(this) } catch (e) {}"> <script>ch("channel1", 1);</script> <script>p(-1,"");</script> <script>p(-1,"");</script> <script>p(2,"channel1","fufufu");</script> <script>p(-1,"");</script> ^C hackman@gamelon:~$Bulgarian Perl Workshop 2013
  16. 16. $ curl http://localhost:4670/push/12345/xhrinteractive/channel1..........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................<script>ch("channel1", 2);</script><script>p(-1,"");</script><script>p(-1,"");</script><script>p(-1,"");</script><script>p(-1,"");</script><script>p(-1,"");</script><script>p(3,"channel1","s1dasda");</script><script>p(-1,"");</script><script>p(-1,"");</script>^Chackman@gamelon:~$ Bulgarian Perl Workshop 2013
  17. 17. $ curl http://localhost:4670/push/12345/simplepoll/channel1<script>ch("channel1", 3);</script>hackman@gamelon:~$$ curl http://localhost:4670/push/12345/smartpoll/channel1<script>ch("channel1", 3);</script>hackman@gamelon:~$$ curl http://localhost:4670/push/12345/longpoll/channel1<script>ch("channel1", 3);</script><script>p(-1,"");</script><script>p(-1,"");</script><script>p(-1,"");</script><script>p(-1,"");</script><script>p(4,"channel1","gtwedsada");</script>hackman@gamelon:~$Bulgarian Perl Workshop 2013
  18. 18. Stand alone web serverAlmost no documentation StardustNo updates since 2011Supports:stream and longpollremove With::Log from stardust.pl cpan StardustBulgarian Perl Workshop 2013
  19. 19. $ curl -d m={ "type": "Test", "data": [1,2,3] } http://localhost:5742/channel/foo/stream/foo//channel/foo/stream/foo/ not found.[root@gamelon script]#hackman@gamelon:~$$ curl -d m={ "type": "Test", "data": [1,2,3] } http://localhost:5742/channel/foo$ curl http://localhost:5742/channel/foo[{"messages":[{"_ts":1360399562.89221,"data":[1,2,3],"type":"Test","_ch":"foo"}], "name":"foo","subscribers":[],"size":8,"i":1}]hackman@gamelon:~$$ curl -d m={ "type": "Test", "data": [2,3] } http://localhost:5742/channel/foo$ curl http://localhost:5742/channel/foo[{"messages":[{"_ts":1360399562.89221,"data":[1,2,3],"type":"Test","_ch":"foo"}, {"_ts":1360399605.81986,"data":[2,3],"type":"Test","_ch":"foo"}], "name":"foo","subscribers":[],"size":8,"i":2}]Bulgarian Perl Workshop 2013
  20. 20. Other Perl comet implementations: - POE-Component-Server-Bayeux - Tatsumaki Additional readings: http://toroid.org/ams/etc/mojolicious-http-streaming http://infrequently.org/2006/03/comet-low-latency-data-for-the-browser/ http://showmetheco.de/articles/2011/2/diving-into-html5-with-websockets-and-perl.htmlBulgarian Perl Workshop 2013
  21. 21. More on the subject here: http://www.slideshare.net/simon/time-for-comet ? ? ? ? ? ? ? ? My slides can be found here: ? http://www.slideshare.net/azilian/perl-cometBulgarian Perl Workshop 2013

×