On Monday 26 November 2001 12:22 am, you wrote:
> On Sun, Nov 25, 2001 at 11:11:09PM -0500, Jason Boxman wrote:
>
>
<snip>
> I don't understand this part.  Artur Bergman, the author of
> Filter::HTTPD, wrote a simple streaming mp3 server that sends headers
> first and then chunks of content later.  Here's the part that answers
> requests:

Actually, what's happening below is almost exactly what I'm working on now, 
with one exception.  The MP3 below is already available on disk.  My 
application is attempting to fetch it via PoCo::Client::UserAgent and return 
it in chunks.

However, during the flush() phase the request is closed and thus if I make a 
$kernel->post('ua'....) there, the file I'm streaming won't be available 
until the HTTP client is long since gone.  This is a bit of a problem for me. 

I ditched the RW Wheel and I'm trying to do all this manually, but now things 
break on my first $driver->flush($my_socket) as the data comes back from LWP. 
If I don't ever flush(), LWP returns all the data in chunks with multiple 
calls to my callback, but without flush()ing everything is broken too.

Is it possible to use a RW Wheel where the flush() doesn't result in the 
death of the socket I'm working with so I can pass off my 2048 byte chunks of 
data back as they're received with LWP?  I'm sure there must be and I'm 
simply not familar enough with POE to understand how to do it, yet, but in 
the meantime I'd appreciate advice from more seasoned developers.

Basically, my app is like httpd.perl, except instead of echoing back the 
request I want to fetch it from another location and return it in small 
blocks to the client.  (Ultimately I'd like to cache to disk first, then read 
the requested file back so multiple things can request said file concurrently 
without the need to download it for each request, but that's for the 
future...)

So, again, thanks for any advice you all have. :)

(I guess I should clean up the code so if anyone wants to see what I actually 
have written you can...)

> sub got_request {
>   my $request = $_[ARG0];
>   print "got $request\n";
>
>   my $response = HTTP::Response->new(200,"Ok");
>   $response->push_header("Content-type", "audio/x-mpeg");
>
>   # Probably could push a content-length header by getting
>   # the size of $mp3_file_name here.
>
>   $_[HEAP]->{wheel}->put($response);
> }
>
> sub got_flush {
>
>   # If the mp3 file isn't open, we've just flushed the headers.
>   # Open the mp3 file here, and switch the filter from HTTPD to
>   # stream.
>
>   unless ($_[HEAP]->{mp3}) {
>     my $mp3 = $_[HEAP]->{mp3} = gensym();
>     open($mp3, "<$mp3_file_name") or die $!;
>
>     $_[HEAP]->{wheel}->set_output_filter(POE::Filter::Stream->new());
>   }
>
>   # Write the next chunk of the mp3 to the client.
>
>   my $read = sysread( $_[HEAP]->{mp3}, my $buffer = '', 4096);
>   if ($read) {
>     $_[HEAP]->{wheel}->put($buffer);
>   }
>   else {
>     $_[HEAP]->{close}++;
>   }
>
>   # If we flushed the last part of the mp3 file, close it and
>   # shut down the server.
>
>   if($_[HEAP]->{close}) {
>     delete($_[HEAP]->{wheel});
>     close $_[HEAP]->{mp3};
>   }
> }
>
> The newline doesn't seem to hurt this application, but the remote
> client is an mp3 player.  Does it really break browsers?
>
> -- Rocco Caputo / [EMAIL PROTECTED] / poe.perl.org / poe.sourceforge.net

Reply via email to