Last active
September 22, 2015 06:21
-
-
Save p120ph37/c2fb59ead8983cdbd130 to your computer and use it in GitHub Desktop.
Perl NPH CGI streaming Comet events
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use warnings; | |
use strict; | |
sub chunk { sprintf "%x\x0D\x0A%s\x0D\x0A", length($_[0]), $_[0]; } | |
$|=1; | |
print "HTTP/1.1 200 Ok\x0D\x0A"; | |
print "Content-Type: text/html\x0D\x0A"; | |
print "Transfer-Encoding: chunked\x0D\x0A"; | |
print "\x0D\x0A"; | |
print chunk((' ' x 1024)."\n"); # enough blank space to break buffering | |
print chunk("<div id=\"counter\">0</div>\n"); | |
for my $i (1..10) { | |
print chunk("<script>document.getElementById('counter').innerHTML='$i';</script>\n"); | |
sleep 1; | |
} | |
print chunk(''); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example running here: https://www.ameriwether.com/cgi-bin/nph-comet.pl