How can I send multiple images in a server push Perl CGI program?

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/21 1:00 UTC
Read the original article Hit count: 224

Filed under:
|
|
|

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 three 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

Related posts about perl

Related posts about cgi