On Thu, Jan 01, 2004 at 02:32:41PM -0600, Jay Strauss wrote:
> Hi,
> 
> I'm can't figure out why I'm getting the error:
> 
> 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.pm line 53.
> 
> With the code below.  The error is occuring in inline_states send_quote
> function, at the put
> 
> The $heap->{server} is of class:
> POE::Wheel::SocketFactory
> 
> I've never had this problem before which leads me to believe its, programmer
> error, but I can't see it

$heap->{server} starts life as a SocketFactory until it has established
a connection.  You can't call put() on a SocketFactory because there's
no remote end to receive anything yet.

One workaround is to wait for the client to be connected.  Something
like this:

> package TradeStudy::TWS;
> 
> use 5.006;
> use strict;
> use warnings;
> use IB::TWS::Contract;
> 
> use POE qw(Component::Client::TCP Filter::Reference);
> use base qw/Class::Accessor/;
> #__PACKAGE__->mk_accessors(qw/last/);
> 
> our $VERSION = sprintf "%d.%03d", q$Revision: 1.19 $ =~ /(\d+)/g;

  my $is_connected = 0;

> POE::Component::Client::TCP->new(
>    RemoteAddress => "localhost",
>    Filter        => "POE::Filter::Reference",
>    RemotePort    => 11011,
>    Alias         => "client_connection",
> 
>    ServerInput => sub {
>       my $response = $_[ARG0];
>       my $heap     = $_[HEAP];
> 
>       %{$heap->{return}}   = %{$response};
>       $heap->{transaction} = undef;
>       ${$heap->{flag}}     = 0;
>    },
> 
>    ServerFlushed => sub {
>       my $heap = $_[HEAP];
>       if ($heap->{transaction} eq "quote") {
>          ${$heap->{flag}} = 0;
>          $heap->{transaction} = undef;
>       }
>    },

     Connected => sub {
       $is_connected = 1;
     }

>    Disconnected => sub {
       $_[KERNEL]->yield("reconnect")
       $is_connected = 0;
     },
> 
>    # Handle some custom events.
>    InlineStates => {
>       send_quote => sub {
>          my ($heap, $flag, $security, $returnValue) =
>             @_[HEAP, ARG0, ARG1, ARG2];
> 
>          my $contract = IB::TWS::Contract->new({
>             symbol   => $security->symbol,
>             secType  => "STK",
>             exchange => "SMART"});
> 
>          $heap->{flag}        = $flag;
>          $heap->{transaction} = "quote";
>          $heap->{returnValue} = $returnValue;
>          $heap->{server}->put($contract);
>       },
> 
>       do_order => sub {
>          my ($heap, $flag, $stuff) = @_[HEAP, ARG0, ARG1];
>          $heap->{server}->put($stuff);
>          $heap->{flag} = $flag;
>          $heap->{transaction} = "order";
>       }
>    },
> );
> 
> sub quote {
>    my ($self, $security) = @_;
>    my $flag = 1;
>    my %returnValue;

     while (!$is_connected) {
       $poe_kernel->run_one_timeslice();
     }

>    $poe_kernel->post(client_connection=>'send_quote',
>       \$flag, $security, \%returnValue);
> 
>    while ($flag) {
>       $poe_kernel->run_one_timeslice();
>    }
> 
>    print %returnValue,"\n";
> 
> }
> 
> sub order {
>   my ($object, $stuff) = @_;

    while (!$is_connected) {
      $poe_kernel->run_one_timeslice();
    }

>   my $flag = 1;
>   $poe_kernel->post(client_connection=>'do_order', \$flag, $stuff);
>   while ($flag) {
>    $poe_kernel->run_one_timeslice();
>   }
> }
> 
> 1;
> __END__

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

Reply via email to