Question on using Filter::Block
"Stefan is using POE" <[email protected]> Sun, 20 Jun 2010 04:22:53 +0200
| Newsgroups | gmane.comp.lang.perl.poe |
|---|---|
| Message-ID | <[email protected]> |
Hello,
I'm new to POE and after a few hours of peeking around, I'm sure, I'll like
it.
Good work!
I need to write a TCP server, grabbing and processing data which are not
line based.
My Data are starting with a header, containing the message length in byte 2
to 4 of my packet.
Currently, I'm reading the first 4 bytes, take the length from bytes 2-4 and
read the rest, which is $lengths-4.
Writing to the client, I build the complete packet and put it on the line.
very basic, but it works. I'm sure, POE will give a better way of doing
this.
I thought, I could use POE::Filter::Block, but this seems to need static
block sizes and the length-prepended, which I do not understand L to use.
As a hint: in the first byte of the packet, there is always 0x07, so it
would be feasible to calculate the length from the first 4 bytes,
subtracting 0x0700000 from it ?!?
I tried to use the following coders and will start everything with
my $filter = POE::Filter::Block->new(LengthCodec => [ \& stefans_encoder, \&
stefans_decoder ] );
sub stefans_decoder {
my $stuff = shift;
$$stuff =~ /^(.)(...)/;
return hex($2);
}
sub stefans_encoder {
my $stuff = shift;
substr($$stuff, 0, 0) = "\7" . sprintf("%06x", length($$stuff));
return;
}
But it does not work.
What would be a good other filter to use or how would I do en
encoder/decoder for Filter::Block?
Any idea?
Thank you.
Stefan