On Sun, Jan 25, 2004 at 02:02:40PM -0600, Jay Strauss wrote:
> 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

I've simplified your test case to

  #!/usr/bin/perl

  use 5.006;
  use strict;
  use warnings;

  use POE qw(Component::Client::TCP Filter::Reference);

  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,
  );

  sub connect {
    warn "connect";
  }

  sub disconnect {
    warn "disconnect";
  }

  sub receive {
    warn "receive";
  }

What strikes me is that you're calling $poe_kernel->run() before you create the
client.  The run() method runs POE until completion---which often involves
every session and component finishing and stopping.

Then you create a client connection, but you don't call run() to execute it.
So this session is built, and then it self-destructs without doing anything
important.

The cvs version of POE, which is being wrapped up for its 0.28 release, doesn't
display anything when either your original or my simplified test cases are
run.

-- 
Rocco Caputo - [EMAIL PROTECTED] - http://poe.perl.org/

Reply via email to