Thanks a ton. The mismatched package names weren't in my copy... I had
renamed them to be a little more polite when I sent them to the list, and
forgotten to rename the package name in the code.

The other changes are most helpful, I'll take a look at them this morning
when I get time.

-----------------------------------------------------------------------------
Brian Knox
Just Another Perl Hacker
perl -le '$_="6110>374086;2064208213:90<307;55";tr[0->][ LEOR!AUBGNSTY];print'

On Thu, 9 Aug 2001 [EMAIL PROTECTED] wrote:

> On Wed, Aug 08, 2001 at 05:17:46PM -0400, [EMAIL PROTECTED] wrote:
> > Well, I've been playing with POE::Component::SubWrapper some, and got it
> > working. Pretty neat.
> >
> > Now I'm trying to use POE::Component::SubWrapper in a little POE program
> > that is supposed to listen on a socket, accept data, use a package wrapped
> > with POE::Component::SubWrapper to process it, and then send some info
> > back.
> >
> > I'm still getting my head wrapped around POE, and something isn't working
> > right probably due to incorrect assumptions on my part. I can telnet to
> > the server (at port 31008) and connect, and send data to it, and it
> > aknowledges it received it.. but the post to the wrapped sub isn't
> > happening, or the callback isn't.. I'm not getting the output from the
> > callback handler.
> >
> > I was wondering if anyone would look at the code (included in the tar
> > file) and let me know what dumb thing I'm doing.
> >
> > Ooops.. I just noticed I left the hmm.. colorful language in my callback
> > that I was using as debugging output, so if you are easily offended, you
> > might not want to look at that particular line too carefully. ;)
>
> I've made a few changes to 3subwrap.pl, shown here. The new version seems
> to work for me.
>
> #!/usr/local/bin/perl -w
>
> use strict;
> use Socket qw( inet_ntoa );
>
> use POE qw (  Wheel::SocketFactory
>               Wheel::ReadWrite
>               Filter::Line
>               Driver::SysRW
>               Component::SubWrapper );
>
> sub POE::Component::SubWrapper::DEBUG() { 1 }
>
> use constant PORT => 31008;
> use TestPoe;
>
> poeize YouSuck;
>
> ^^^^^^^^^^^^^^^^^^^^^^^^
> All your stuff is in the YouSuck package, despite the fact the file is
> called TestPoe, so you need to poeize YouSuck.
>
> POE::Session->create (
>       inline_states => {
>               _start => \&server_start,
>               _stop => \&server_stop,
>               callback => \&child_callback,
>       }
> );
>
> $poe_kernel->run();
> exit;
>
> sub server_start {
>       $_[HEAP]->{listener} = new POE::Wheel::SocketFactory (
>               BindPort        => PORT,
>               Reuse           => 'yes',
>               SuccessState    => \&accept_new_client,
>               FailureState    => \&accept_failed
>       );
> }
>
> sub server_stop {
>       print "SERVER: Stopped.\n";
> }
>
> sub accept_new_client {
>       my ($socket, $peeraddr, $peerport) = @_[ARG0 .. ARG2];
>       $peeraddr = inet_ntoa($peeraddr);
>
>       new POE::Session (
>               _start  => \&child_start,
>               _stop   => \&child_stop,
>     callback => \&child_callback,
>
> ^^^^^^^^^^^^^^^^^
> You're calling back to this session, and it didn't have a callback state
>
>               main    => ['child_input', 'child_done', 'child_error'],
>               [ $socket, $peeraddr, $peerport ]
>       );
>
>       print "SERVER: Got connection from $peeraddr:$peerport.\n";
> }
>
> sub accept_failed {
>       my ($function, $error) = @_[ARG0, ARG2];
>       delete $_[HEAP]->{listener};
>       print "SERVER: call to $function() failed: $error \n";
> }
>
> sub child_start {
>       my ($heap, $socket) = @_[HEAP, ARG0];
>       $heap->{readwrite} = new POE::Wheel::ReadWrite (
>               Handle          => $socket,
>               Driver          => new POE::Driver::SysRW(),
>               Filter          => new POE::Filter::Line(),
>               InputState      => 'child_input',
>               ErrorState      => 'child_error',
>               Callback        => 'child_callback',
>
> ^^^^^^^^^^^^^^^^^^^^
> Poe doesn't seem to like this, not sure why.
>
>       );
>       $heap->{readwrite}->put( "Hello, client!" );
>       $heap->{peername} = join ':', @_[ARG1, ARG2];
>       print "CHILD: Connected to $heap->{peername}. \n";
> }
>
> sub child_input {
>       my $data = $_[ARG0];
>       return unless length $data;
>       $poe_kernel->post('YouSuck', 'testpoe', ["$data"], 'callback', 'SCALAR');
>
> ^^^^^^^^^^^^^
> Had to change this package
>
>       print "CHILD: Got input from peer: \"$data \n \n";
>       $_[HEAP]->{readwrite}->put( "Received data from you: $data" );
> }
>
> sub child_done {
>       delete $_[HEAP]->{readwrite};
>       print "CHILD: disconnected from ", $_[HEAP]->{peername}, ".\n";
> }
>
> sub child_error {
>       my ($function, $error) = @_[ARG0, ARG2];
>       delete $_[HEAP]->{readwrite};
>       print "CHILD: call to $function() failed $error. \n" if $error;
> }
>
> sub child_callback {
>       print "FUCKER!\n";
> }
>
>
> Michael
>

Reply via email to