in reply to Re^2: POE method problem (building applications with POE)
in thread POE method problem (building applications with POE)

I don't have POE installed on this PC, but I'm pretty sure the reason you're losing your connection when you get a new one is your factory_success method.

When you create a connection, you store it as:

$_[HEAP]->{clients}->{$wheel_id} = $temp_rw_id;
But $wheel_id is the same from one connection to another, so when the next connection comes along, you overwrite the last reference to the previous Wheel:RW, and it gets destroyed.

Try keeping a hash of active wheels, something like

$_[HEAP]->{clients}->{$wheel_id}->{$temp_rw_id}=undef;
instead. When you're done with a wheel, just "delete" it from that hash.

This way, you're keeping a live reference to all active wheels.

Hope this helps!


Mike

Replies are listed 'Best First'.
Re^4: POE method problem (building applications with POE)
by Orchid_NL (Novice) on Jan 08, 2005 at 12:24 UTC
    Hi Mike, thanks for your reply.

    The nice editors from perl.com fixed the download link after I mailed them.
    The downloaded code clears up alot of things.
    The wheel-id from POE::Wheel::SocketFactory is indeed the same throughout the whole program run.
    Only the wheel-id in POE::Wheel:ReadWrite is different for each connection. This is the only wheel-id that needs to be stored (and destroyed).

    I changed subroutines 'factory_success' and 'client_input' accordingly and it works now!

    The code in the perl.com article and the code made available through the download link are different from each other which is a confusing for a POE newbie like me ;-)

    sub factory_success { my $handle = $_[ARG0]; my $wheel_id = POE::Wheel::ReadWrite->new( Handle => $handle, Driver => POE::Dri +ver::SysRW->new(), Filter => POE::Fil +ter::SimpleQueryString->new(), InputEvent => 'client_ +input', ); $_[HEAP]->{clients}->{$wheel_id->ID} = $wheel_id; } sub client_input { my ($input, $wheel_id) = @_[ARG0, ARG1]; use Data::Dumper; print Dumper $input; $_[HEAP]->{clients}->{$wheel_id}->put($input); }