Hi,

I have the following code.  But the "connect" sub gets called regardless of
whether there is a connection or not (I don't even have the server running
for the test).  Which in turn produces:

Can't locate object method "put" via package "POE::Wheel::SocketFactory"
(perhaps you forgot to load "POE::Wheel::SocketFactory"?) at
/home/jstrauss/tradestudy/lib/perl/TradeStudy/TWS_Client.pm line 50.

when I call "quote".

If I move the $poe_kernel->run(), below the POE::Component::Client::TCP
block then I get a connection error (like I expect).

I can't see why "connect" is getting called, before a real connection is
made.  I can't see my problem (I could have sworn I had this working 3 weeks
ago).  Could someone point me in the right direction.

Thanks
Jay


package TradeStudy::TWS_Client;

use 5.006;
use strict;
use warnings;

use POE qw(Component::Client::TCP Filter::Reference);
use base qw/Class::Accessor/;

my $is_connected = 0;

$poe_kernel->run();

POE::Component::Client::TCP->new(
        RemoteAddress => "localhost",
        Filter        => "POE::Filter::Reference",
        RemotePort    => 12001,
        Alias         => "client_connection",
        Connected     => \&connect,
        Disconnected  => \&disconnect,
        ServerInput   => \&receive,
        InlineStates  => {xmit=>\&xmit},
);

sub connect {
        print "HERE\n";
        $is_connected = 1;
}

sub disconnect {
        $_[KERNEL]->yield("reconnect");
        $is_connected = 0;
}

sub receive {
        my ($heap,$r) = @_[HEAP,ARG0];

        ${$heap->{retVal}}  = $r;
        ${$heap->{wait}} = 0;
}

sub xmit {
        my ($heap,$arg) = @_[HEAP,ARG0];

        $heap->{retVal} = $arg->{retVal};
        $heap->{wait}   = $arg->{wait};

        $heap->{server}->put([$arg->{subName}, $arg->{parms}]);
}

sub quote {

        my $self = shift;
        my $r;
        my $wait = 1;

        $poe_kernel->post(client_connection=>xmit=>{
                wait    => \$wait,
                retVal  => \$r,
                subName => 'quote',
                parms   => [qw(this that)]
                }
        );

        while ($wait) {
                $poe_kernel->run_one_timeslice();
        }
}

sub DESTROY {
        $poe_kernel->yield("shutdown");
}

1;


Reply via email to