私は Perl CGI などの初心者です。Perl コードを使用してサーバー プッシュの概念を試していました。3 秒ごとに jpeg 画像をクライアントに送信することになっています。
残念ながら、何も機能していないようです。誰かが問題を特定するのを助けることができますか?
コードは次のとおりです。
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;
}
編集: I/O バッファリングをオフにする機能を追加、「use strict」と「@file_list」、「$file」をローカルに追加