perl comet
TRANSCRIPT
Comet implementations for Perl
Bulgarian Perl Workshop 2013
Marian HackMan MarinovCo-founder and CEO of 1H [email protected]
Bulgarian Perl Workshop 2013
What is Comet?
AJAX Push
Reverse AJAXTwo-way-webHTTP Streaming
HTTP Server Push
Replacing browser PULLwith server PUSH
A lot of names for the same technology :)
Bulgarian Perl Workshop 2013
Implementations
Hidden iframeXMLHttpRequestlong polling with- AJAX- XMLHttpRequest- Script tag
Bulgarian Perl Workshop 2013
StreamingShort pollingLong polling
Bulgarian Perl Workshop 2013
Hidden iframe
Iframe sent as chunked blcok
Infinitely long
Works on every browser
Lacks reliable error handlingConnection state unavailable
Does not support cross domain accessBefore IE needs minimum 256bytes of data before executing anythingThe same issue is present in Safari
Bulgarian Perl Workshop 2013
hackman@gamelon:~$ curl http://localhost:4670/push/12345/iframe/channel1
document.getElementById('counter').innerHTML = '1';document.getElementById('counter').innerHTML = '2';document.getElementById('counter').innerHTML = '3';document.getElementById('counter').innerHTML = '4';document.getElementById('counter').innerHTML = '5';document.getElementById('counter').innerHTML = '6';
Comet test Page
My counter:
Bulgarian Perl Workshop 2013
XMLHttpRequest
The Ajax way of using CometReliable connection handlingConnection state information
Content-type: multipart/x-mixed-replace; boundary=NEXTPART\r\n\r\n
x-mixed-replace is invented by Netscape 1995since 2004 has support in Gecko browsersit is also included in IE 10 and newerDoes not support cross domain access
Bulgarian Perl Workshop 2013
hackman@gamelon:~$ curl http://localhost:8000/
--NEXTPARTContent-type: text/plain
document.getElementById('counter').innerHTML = '0';--NEXTPARTContent-type: text/plain
document.getElementById('counter').innerHTML = '1';--NEXTPARTContent-type: text/plain
document.getElementById('counter').innerHTML = '2';--NEXTPART
Bulgarian Perl Workshop 2013
Long Polling
XMLHttpRequest - creates a request- when all data is received- creates subsequent request
Does not support cross domain accessWorks on all browsers
Bulgarian Perl Workshop 2013
Long Polling
tag- creates a script tag- when all data is received- creates new script tag
Supports cross domain accessWorks on all browsers
Bulgarian Perl Workshop 2013
What Comet implementationswe have in Perl
MeteorStardust
Frameworks: - Mojolicious - PSGI
- Continuity
You can do it with CGI.pm but it is not advisable
Bulgarian Perl Workshop 2013
Meteor
Stand alone web serverSupports: - iframe - xhrinteractive- simplepoll & smartpoll- longpoll- flash & flashloadvars
http://meteorserver.org/
Meteor
You can do it with CGI.pm but it is not advisable
Bulgarian Perl Workshop 2013
ADDMESSAGE chan msg COUNTSUBSCRIBERS chan LISTCHANNELS SHOWSTATS QUIT
Event controller commands
You can do it with CGI.pm but it is not advisable
Bulgarian Perl Workshop 2013
hackman@gamelon:~/Comet$ nc localhost 4671SHOWSTATSOKuptime: 279channel_count: 0subscriber_connections_accepted: 3controller_connections_accepted: 1total_inbound_bytes: 524total_outbound_bytes: 646documents_not_found: 3current_controllers: 1total_requests: 4current_subscribers: 0--EOT--ADDMESSAGE channel1 testingOK 0LISTCHANNELSOKchannel1(1/0)--EOT--ADDMESSAGE channel1 ddddddOK 1
You can do it with CGI.pm but it is not advisable
Bulgarian Perl Workshop 2013
$ curl http://localhost:4670/push/12345/iframe/channel1
window.onError = null;var domainparts = document.domain.split(".");document.domain = domainparts[domainparts.length-2]+". "+domainparts[domainparts.length-1];parent.Meteor.register(this);
ch("channel1", 1);
p(-1,"");p(-1,"");p(2,"channel1","fufufu");p(-1,"");^Chackman@gamelon:~$
You can do it with CGI.pm but it is not advisable
Bulgarian Perl Workshop 2013
$ curl http://localhost:4670/push/12345/xhrinteractive/channel1..........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................ch("channel1", 2);p(-1,"");p(-1,"");p(-1,"");p(-1,"");p(-1,"");p(3,"channel1","s1dasda");p(-1,""); p(-1,""); ^C hackman@gamelon:~$
You can do it with CGI.pm but it is not advisable
Bulgarian Perl Workshop 2013
$ curl http://localhost:4670/push/12345/simplepoll/channel1 ch("channel1", 3); hackman@gamelon:~$
$ curl http://localhost:4670/push/12345/smartpoll/channel1ch("channel1", 3); hackman@gamelon:~$
$ curl http://localhost:4670/push/12345/longpoll/channel1 ch("channel1", 3); p(-1,""); p(-1,""); p(-1,""); p(-1,""); p(4,"channel1","gtwedsada"); hackman@gamelon:~$
You can do it with CGI.pm but it is not advisable
Bulgarian Perl Workshop 2013
Stand alone web serverAlmost no documentationNo updates since 2011Supports: stream and longpoll
cpan Stardust
Stardust
remove With::Log from stardust.pl
cpan Stardust
You can do it with CGI.pm but it is not advisable
Bulgarian Perl Workshop 2013
$ 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}]
You can do it with CGI.pm but it is not advisable
Bulgarian Perl Workshop 2013
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.html
You can do it with CGI.pm but it is not advisable
Bulgarian Perl Workshop 2013
?
?
?
?
?
?
?
?
?
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-comet
More on the subject here: http://www.slideshare.net/simon/time-for-comet
You can do it with CGI.pm but it is not advisable