Hi Monks,

I'm currently stuck with a piece of POE code. Here is a slightly stripped versions:
#!perl use warnings; use strict; use diagnostics; use IO::Socket; use POE qw(Wheel::SocketFactory Wheel::ReadWrite); my $SERVER_ADDR = '192.168.178.6'; my $SERVER_PORT = '50099'; POE::Session->create( inline_states => { _start => sub { # Start the server. $_[HEAP]{server} = POE::Wheel::SocketFactory->new( RemoteAddress => $SERVER_ADDR, RemotePort => $SERVER_PORT, SocketProtocol => 'udp', SuccessEvent => "on_connect", FailureEvent => "on_server_error", ); }, on_connect => sub { # Begin interacting with the server. my $kernel = $_[KERNEL]; my $client_socket = $_[ARG0]; my $io_wheel = POE::Wheel::ReadWrite->new( Handle => $client_socket, InputEvent => "on_receive_data", ErrorEvent => "on_connect_error", ); $_[HEAP]{client}{ $io_wheel->ID() } = $io_wheel; $io_wheel->put( "login monitor monitor", "log on", ); $kernel->yield('keepalive', $io_wheel, $kernel); }, on_server_error => sub { # Shut down server. my ( $operation, $errnum, $errstr ) = @_[ ARG0, ARG1, ARG2 + ]; warn "Server $operation error $errnum: $errstr\n"; delete $_[HEAP]{server}; }, on_receive_data => sub { # Handle client input. my ( $kernel, $input, $wheel_id ) = @_[ KERNEL, ARG0, ARG1 + ]; print "Received: $input\n"; }, on_connect_error => sub { # Handle client error, including disconnect. my $wheel_id = $_[ARG3]; delete $_[HEAP]{client}{$wheel_id}; }, keepalive => sub { my ( $io_wheel, $kernel ) = @_[ ARG0, ARG1 ]; $io_wheel->put( "keepalive" ); $kernel->delay_add( 'keepalive' => 10 ); }, } ); POE::Kernel->run(); exit;
My intention is to create a timer that calls
keepalive => sub { my ( $io_wheel, $kernel ) = @_[ ARG0, ARG1 ]; $io_wheel->put( "keepalive" ); $kernel->delay_add( 'keepalive' => 10 );
every 10 seconds. The first call to this sub works and the server, to which this client connects, sends the expected answer. After 10 seconds the sub is called again and it always ends up with:
Uncaught exception from user code: Can't call method "put" on an undefined value at fac.pl line 5 +9. at /usr/local/share/perl/5.14.2/POE/Kernel.pm line 1256 POE::Kernel::_rethrow_kr_exception('POE::Kernel=ARRAY(0x88f2e8 +)') called at /usr/local/share/perl/5.14.2/POE/Kernel.pm line 1244 POE::Kernel::run('POE::Kernel') called at fac.pl line 65
Any help would be really appreciated

In reply to POE yield not working by SoulStyle

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.