All pastes #799413 Raw Edit

K0brik

public text v1 · immutable
#799413 ·published 2007-11-27 16:59 UTC
rendered paste body
#!/usr/bin/perl -w

use strict;
use warnings;

use IO::Socket::INET;

my $socket = new IO::Socket::INET (
                                Listen => 5,
                                LocalAddr => 'localhost',
                                LocalPort => 8000,
                                Proto => 'tcp');

while (my $cli_sock =  $socket->accept) {
        cast ($cli_sock) if !fork;
}

sub cast {
        my $socket = shift;

        #print the HTTP header.  The only thing really necessary
        #   is the first line and the trailing "\n\n"
        #   depending on your client (like xmms) you can also
        #   send song title etc.
        print $socket "HTTP/1.0 200 OK\n";
        print $socket "Content-Type: audio/x-mp3stream\n";
        print $socket "Cache-Control: no-cache \n";
        print $socket "Pragma: no-cache \n";
        print $socket "Connection: close \n";
        print $socket "x-audiocast-name: My MP3 Server\n\n";

        open SND, '<06 Lucretia.mp3' or die "oops: $!\n";

        $/ = \1024;

        while (<SND>) {
                print $socket $_;
        }
}