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.

My current design (plain IO::Socket):

Reading: I'm reading the first 4 bytes (local $/= \4), take the length from
bytes 2-4 and then read the rest, which is $lengths-4.

Writing: 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 or the length-prepended configuration, 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.

If I Telnet to this server, typing the first letter loops in messages
warning "Use of uninitialized value in hex"

 

I extended the encoder to get some more information:

sub stefans_decoder {

  my $stuff = shift;

  print "= D = stuff: ".$$stuff."\n";

  $$stuff =~ /^(.)(...)/;

  print "= D = stuff: ".$$stuff."\n";

  die;

  return hex($2);

}

 

It prints the typed character twice, but returns without waiting for the
next 3 bytes to get the length.

 

 

 

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

Reply via email to