I have a problem using the POE TCP components to send the data packets between machines. The file that I used at the sender part has a size of 14kb. But I can only receive about 10kb. It got chunked even though I did specify the buffer size of 65535 at the sender part.
use warnings;
use strict;
use POE qw(Component::Server::TCP);
POE::Component::Server::TCP->new(
Port => 12345,
ClientFilter => "POE::Filter::Stream",
ClientConnected => sub {
print "got a connection from $_[HEAP]{remote_ip}\n";
my $buffer;
open FILE, "file" or die "Couldn't open file: $!";
while (<FILE>){
$buffer .= $_;
}
close FILE;
$_[HEAP]{client}->put($buffer);
},
ClientInput => sub {
my ($client_input, $heap) = @_[ARG0, HEAP];
push @{ $heap->{banner_buffer} }, $client_input;
},
ClientDisconnected => sub {
print "client from $_[HEAP]{remote_ip} disconnected\n";
},
InlineStates =>
{ input_display=>sub{
my ($client_input, $heap) = @_[ARG0, HEAP];
foreach ( @{ $heap->{banner_buffer} } ) {
print "|| $_";
}
}
},
);
POE::Kernel->run;
exit;
use strict;
use warnings;
use File::Basename;
use lib dirname($0) . "/lib";
use POE;
use POE::Component::Client::TCP;
use POE::Filter::Stream;
use Data::Dumper;
my $port = "12345" ;
my $host = "localhost";
_tcpConnection();
POE::Kernel->run;
exit;
sub _tcpConnection{
POE::Session->create(
inline_states=>{
_start=>sub {
$_[KERNEL]->alias_set("Connection");
my ( $kernel, $heap ) = @_[ KERNEL, HEAP ];
POE::Component::Client::TCP->new
( RemoteAddress => $host,
RemotePort => $port,
Filter => "POE::Filter::Stream",
Connected => sub {
print "sending request on $host:$port ...\n
+";
$_[HEAP]->{server}->put("connect"); # sends
+ connect
$_[HEAP]->{banner_buffer} = [];
},
# The connection failed.
ConnectError => sub {
print "could not connect to $host:$port ...\n"
+;
},
ServerInput => sub {
my ( $kernel, $heap, $input ) = @_[ KERNEL, HE
+AP, ARG0 ];
print "input $input\n";
push @{ $heap->{banner_buffer} }, $input;
$kernel->delay( input_timeout => 20 );
},
InlineStates =>
{
input_timeout => sub {
print "got input timeout from $host:$port
+...\n";
print ",----- Banner from $host:$port\n";
foreach ( @{ $heap->{banner_buffer} } ) {
print "| $_";
}
print "`-----\n";
#$kernel->yield("shutdown");
},
},
);
},
},
),
}
Thanks in advance.