Hi,

I'd like to build an object, which would connect (via
POE::Component::Client::TCP) to my POE server.  I want the object to keep
the connection open so that I could call the methods and perform useful
tasks without having to connect - disconnect within each of my objects
methods.

Sorta like (pseudo code):

package TWS;

POE::Component::Client::TCP->new(...);

sub quote {
    # send @_ to the server
    # process the data sent back by server
}

sub order {
    # send @_ to the server
}


### then in a nearby piece of code:
my $tws = TWS->new;
$tws->quote('IBM');
$tws->order(10,'IBM');

But instead I keep having to POE::Component::Client::TCP->new(...) and
shutdown in every method.  I'm I trying to fit a square peg in a round hole?
I've been doing it like (below) but its kinda gross:

package TWS;

sub quote {

    POE::Component::Client::TCP->new(
        ...
        Args            => [EMAIL PROTECTED],
        Started         => sub {..},
        Connected       => sub {
            ...
           $heap->{server}->put(\$stuff);
            }
        },

        ServerInput     => sub {
            ...
            $kernel->yield( "shutdown" );
        },
    );

    $poe_kernel->run();
}

sub order {

    POE::Component::Client::TCP->new(
        ...
        Args            => [EMAIL PROTECTED],
        Started         => sub {..},
        Connected       => sub {
            ...
           $heap->{server}->put(\$stuff);
            }
        },

        ServerInput     => sub {
            ...
            $kernel->yield( "shutdown" );
        },
    );

    $poe_kernel->run();
}

1;

Thanks
Jay

Reply via email to