我是 Perl CGI 等方面的初学者。我正在用一段 Perl 代码试验服务器推送概念。它应该每三秒向客户端发送一个 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 缓冲,添加“使用严格”和“@file_list”,“$file”被设为本地