L
Larry
Hi guys!
below is the code I've been working on lately...it acts as if he can
handle multiple connections and sends an mp3 file to the browser (IE5)...
#!/perl
use strict;
use warnings;
use IO::Socket;
use IO::Select;
my $socket = IO::Socket::INET->new(LocalPort => '81', Proto => 'tcp',
Type => SOCK_STREAM, Reuse => 1, Listen => 10) || die "$!\n";
my $sel = new IO::Select();
$sel->add( $socket );
my ($fh,$rh_set,$ns,$content,@ready,$file);
while (1)
{
@ready = $sel->can_read;
foreach $fh ( @ready ) {
if ($fh == $socket)
{
$ns = $socket->accept;
$sel->add($ns);
} else {
recv($fh,$content,10000,0);
print $content;
syswrite $fh, "HTTP/1.1 200 OK\n";
syswrite $fh, "Apache/1.3.0 (unix)\n";
syswrite $fh, "Cache-Control: no-cache\n";
syswrite $fh, "Content-type: application/octet-stream\n";
syswrite $fh, "Content-Disposition: attachment;
filename=stuck.mp3\n";
syswrite $fh, "\n";
open(BYNA, "<stuck.mp3") || die "$!\n\n";
binmode(BYNA);
while( read(BYNA,$file,1024) )
{
syswrite $fh, $file;
}
close(BYNA);
$sel->remove($fh);
$fh->close;
}
}
}
__END__;
unfortunately when i close the connection at the browser side (by
pressing X) or when i refuse the download (by pressing "cancel") the
script dies...(without any error) or i'd say the script exits (so i've
got to run it again...how boring)
I can not really sort it out...
can anyone help with this?
thanks
below is the code I've been working on lately...it acts as if he can
handle multiple connections and sends an mp3 file to the browser (IE5)...
#!/perl
use strict;
use warnings;
use IO::Socket;
use IO::Select;
my $socket = IO::Socket::INET->new(LocalPort => '81', Proto => 'tcp',
Type => SOCK_STREAM, Reuse => 1, Listen => 10) || die "$!\n";
my $sel = new IO::Select();
$sel->add( $socket );
my ($fh,$rh_set,$ns,$content,@ready,$file);
while (1)
{
@ready = $sel->can_read;
foreach $fh ( @ready ) {
if ($fh == $socket)
{
$ns = $socket->accept;
$sel->add($ns);
} else {
recv($fh,$content,10000,0);
print $content;
syswrite $fh, "HTTP/1.1 200 OK\n";
syswrite $fh, "Apache/1.3.0 (unix)\n";
syswrite $fh, "Cache-Control: no-cache\n";
syswrite $fh, "Content-type: application/octet-stream\n";
syswrite $fh, "Content-Disposition: attachment;
filename=stuck.mp3\n";
syswrite $fh, "\n";
open(BYNA, "<stuck.mp3") || die "$!\n\n";
binmode(BYNA);
while( read(BYNA,$file,1024) )
{
syswrite $fh, $file;
}
close(BYNA);
$sel->remove($fh);
$fh->close;
}
}
}
__END__;
unfortunately when i close the connection at the browser side (by
pressing X) or when i refuse the download (by pressing "cancel") the
script dies...(without any error) or i'd say the script exits (so i've
got to run it again...how boring)
I can not really sort it out...
can anyone help with this?
thanks