Server Push CGI Perl Problem writing the JPEG image
Posted
by Jujjuru
on Stack Overflow
See other posts from Stack Overflow
or by Jujjuru
Published on 2010-05-20T05:38:21Z
Indexed on
2010/05/20
6:10 UTC
Read the original article
Hit count: 247
I am a beginner in Perl CGI etc. I was experimenting with server-push concept with a piece of perl code. It is supposed to send a jpeg image to the client every 3 seconds.
Unfortunately nothing seems to work. Can somebody help identify the problem?
Here is the code....
use strict;
# turn off io buffering
$|=1;
print "Content-type: multipart/x-mixed-replace;";
print "boundary=magicalboundarystring\n\n";
print "--magicalboundarystring\n";
#list the jpg images
my(@file_list) = glob "*.jpg";
my($file) = "";
foreach $file(@file_list )
{
open FILE,">", $file or die "Cannot open file $file: $!";
print "Content-type: image/jpeg\n\n";
while ( <FILE> )
{
print "$_";
}
close FILE;
print "\n--magicalboundarystring\n";
sleep 3;
next;
}
EDIT: added turn off i/o buffering, added "use strict" and "@file_list", "$file" are made local
© Stack Overflow or respective owner