Hello Monks,
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.

Has anyone run into this problem before? Thanks so much.
Here's the code

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;


Updated!

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.

In reply to 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.