spiros has asked for the wisdom of the Perl Monks concerning the following question:

Wise Monks, I ask thee: Is there a way to calculate the connection time for a multimedia stream, for example:
http://www.bbc.co.uk/radio2/realmedia/fmg2.ram
What I basically need is the elapsed time until the first bit of data is received. I've tried several bits and pieces but have failed as of yet to get a valid response. Thank you in advance.

Replies are listed 'Best First'.
Re: elapsed connection response time
by BrowserUk (Patriarch) on Jul 25, 2007 at 15:47 UTC

    Is this accurate enough for your purposes?

    #! perl -slw use strict; use Time::HiRes qw[ time ]; use IO::Socket::INET; my $s = IO::Socket::INET->new( 'www.bbc.co.uk:80' ) or die "$!, $^E"; my $start = time; print {$s} 'GET //realmedia/fmg2.ram HTTP/1.0', "\n"; my $read; read( $s, $read, 15 ); printf "First 15 bytes ('$read') took %.3f seconds\n", time() - $start +; __END__ C:\test>junk5 First 15 bytes ('HTTP/1.1 200 OK') took 0.402 seconds C:\test>junk5 First 15 bytes ('HTTP/1.1 200 OK') took 0.572 seconds

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re: elapsed connection response time
by almut (Canon) on Jul 25, 2007 at 16:10 UTC

    If you're interested in the time it takes until the first byte of the actual media stream arrives, I think you'll need to do it in two steps, because the initial HTTP connection will only return a rtsp://... URI like this:

    rtsp://rmlive.bbc.co.uk/bbc-rbs/rmlive/ev7/live24/radio2/live/r2_dsat_ +g2.ra?BBC-UID=b4361a170730f2451b5b6f95f05099551b1f970a5060d0735b4a906 +b12583889&SSO2-UID=

    So you'll need to also connect to that URI in a second step (using the technique suggested by BrowserUk), and measure the total time of the two connects.  IIRC, the default port for the RTSP protocol is 554 (but be sure to verify that before trying...)

    Update: actually, it seems you might need to jump through even more hoops to get at the actual stream...  Just read up a bit on that myself, and apparently there are other additional protocols involved: SDP (Session Description Protocol), RTP (Real-time Transport Protocol), RTCP (Real-time Transport Control Protocol), and possibly others... ;)

    All in all, it might take quite a bit of reading until you're sufficiently knowledgeable to be able to low-level emulate everything that some media player program is doing behind the scenes... In other words, some more "end-to-end" approach might ultimately be more promising (like tracing network traffic with wireshark, or some such). But before going into that, I'd first spend some time googling to see if not anyone else has already figured it out and written a nice tool like ab (ApacheBench), only for benchmarking media streams... :)  Good luck!

      thank you for your replies guys. I will check it out.