Are you sure you want to be using sysread? Something about this doesn't feel right.

ClientConnected => sub { print "got a connection from $_[HEAP]{remote_ip}\n"; open(INFILE,"./file") or die "Open fail"; sysread(INFILE,my $buffer='',65535); $_[HEAP]{client}->put($buffer); },

Either way, there's an awful lot of code in your post. I couldn't begin to guess where the problem is. Perhaps you could narrow it down to a smaller example?

I do recall having various problems with the TCP classes. IIRC, I ended up writing a POE::Filter (which you plug in with the ClientFilter keyvar) that encoded unprintable characters and CRFLs into a format that wouldn't mess with line buffering and the problems went away. Technically the filter also encrypted the messages...

package cbcfilter; use strict; use POE::Filter; use Crypt::CBC; use MIME::Base64; use CGI qw(escape unescape); our @ISA = qw(POE::Filter); use Carp qw(carp croak); sub BUFFER () { 0 } sub CIPHER () { 1 } # NOTE: no worries, $filter->clone() gets called for every new client +and this # bless is completely compatible with the clone we inherit from the IS +A ablove # (including clearing the buffer). :) sub new { my $class = shift; my $file = shift; my $obtai = shift; my $key; if( $file and -f $file ) { open my $keyio, $file or croak "couldn't open keyfile=\"$file\ +": $!"; local $/ = undef; my $entire_key = <$keyio>; close $keyio; $key = decode_base64( $entire_key ); } croak "no keyfile specified or no key found inside it (file=$file) +" unless $key; my $cbc = Crypt::CBC->new({ key=>$key, cipher=>'Blowfish', header= +>"randomiv" }); return bless [ '', $cbc ], $class; } sub get_one_start { my ($this, $stream) = @_; local $" = ""; $this->[BUFFER] .= "@$stream"; } sub get_one { my $this = shift; if( $this->[BUFFER] =~ s/<msg>([^<>]*)<\/msg>//s ) { my $msg = $1; return [] unless length $msg and $msg =~ m/RandomIV/; return [ $this->[CIPHER]->decrypt( unescape($msg) ) ]; } return []; } sub put { my ($this, $msgs) = @_; my $cbc = $this->[CIPHER]; my @ret = (); for my $msg ( @$msgs ) { $msg = escape( $cbc->encrypt($msg) ); push @ret, "<msg>$msg</msg>"; } return \@ret; } sub get_pending { my $this = shift; return [ $this->[BUFFER] ] if length $this->[BUFFER]; return undef; } 1;

I always expected I was missing something though. I don't think it's line buffered.

-Paul


In reply to Re: sending data over TCP channel using POE::Component::Server::TCP by jettero
in thread sending data over TCP channel using POE::Component::Server::TCP by cta

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.