http://qs1969.pair.com?node_id=534551

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

*Update - I found a solution and have posted the basic code which implements SmackFu's algorithm, written in pure perl, see the replys

I'm trying to read a stream of bytes, sent over http (yes), and read specific bytes out of it. I'm finding, incredulously, that I don't know how to determine the integer value of a byte. Some context:

my $sock = Net::HTTP->new(Host => "server.com") || die $@; $sock->write_request(GET => "bytestream") or die $@; $sock->read_response_headers( ); #i don't need these while(1){ $s->recv($buf, $size); my $n = length($buf); # oh.. i feel like reading byte #4 today. next if $n < 4; # i don't want to talk about this case, ok? my $byte = bytes::substr($buf, 4, 1, undef); #remove it from the stream too print $byte; #not looking like an integer. $byte *= 16; #yields a warning: # Argument "x" isn't numeric ...etc # where "x" is some crazy character }
I have a hunch ord($byte) is what i'm looking for, but the byte i'm reading isn't yielding the value I expect it to, which could be a different problem...

for the more curious, I'm attempting to implement an icecast stream recorder, the stream format is explained here: http://www.smackfu.com/stuff/programming/shoutcast.html
i'm storing the metaint from the headers, just not in my example, and yes the "byte" i'm trying to read is that meta length byte - my next question will be how to convert the meta data (string of bytes) into a character string. then writing to disk (and prefiltering) only the mpg frames, none of the metadata.

maybe somebody will recommend other solutions to reimplementing the wheel, which I'm open to, but my requirements are highly specific and I haven't found anything that can meet them all, so here we are.


It's not what you look like, when you're doin' what you’re doin'.
It's what you’re doin' when you’re doin' what you look like you’re doin'!
     - Charles Wright & the Watts 103rd Street Rhythm Band