*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
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.