logo       
Google Custom Search
    AddThis Social Bookmark Button

using POE in a object being called procedurally: msg#00013

Subject: using POE in a object being called procedurally
Hi, I haven't used POE in a long time and now everything I once knew is gone. I feel like I'm heading down the wrong path and there is probably a specific way to do this.

I want to build an object that communicates with a Component::TCP::Server. This object will be instantiated by various scripts (I have yet to write). The scripts will want to talk to the server once in a while, that is they will not be in a POE event loop.

I can't think how I'm supposed to get "quote" to talk to the server, and once the server talks back (sending data), I don't know how I'm going to get this out of the POE area, and into my general program.

I started off like (below), but with this route I'm going to need all kinds of global variables where my POE parts can communicate with my procedural parts, and my procedural parts can see if POE is done...

Is there a better way?
thanks
Jay

package TradeStudy::BrokerClient;

use 5.008004;
use strict;
use warnings;

use base qw(Class::Accessor);
use POE qw(Component::Client::TCP Filter::Reference);
sub new {

   my $class = shift;
   my $arg = shift;

   $arg = {} unless defined $arg;

   $arg->{_poe} =
      POE::Component::Client::TCP->new(
         RemoteAddress => "localhost",
         RemotePort    => 11001,
         Filter        => "POE::Filter::Reference",
         ServerInput   => sub {
            my $input = $_[ARG0];
            print "from server: $input\n";
         },
         Connected => \&connected,
         InlineStates => {
            send_quote => \&send_quote,
         },
      );

   return $class->SUPER::new($arg);
}

sub get_quote {

   my $self = shift;
   my $args = shift;

   foreach my $security (@_) {

      $g_input = 0;

      # Gotta figure out how to get at $kernel and $heap
      $heap->{server}->put(["quote", %$args]);

      while (! $g_input) {
         $kernel->run_one_timeslice;
      }

      push $self->data, $g_input;
   }
}

sub server_input {
   $g_input = $_[ARG0];
}


1;




Try Searching:
servers, voip, java, networking, microsoft ...
<Prev in Thread] Current Thread [Next in Thread>