in reply to sending data over TCP channel using POE::Component::Server::TCP
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: sending data over TCP channel using POE::Component::Server::TCP
by cta (Acolyte) on Jul 30, 2008 at 15:36 UTC |