Rocco Caputo > POE-Stage > POE::Stage::Receiver

Download:
POE-Stage-0.060.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  0
View/Report Bugs
Source  

NAME ^

POE::Stage::Receiver - a simple UDP recv/send component

SYNOPSIS ^

        # Note, this is not a complete program.
        # See the distribution's examples directory.

        use POE::Stage::Receiver;
        my $stage = POE::Stage::Receiver->new();
        my $request = POE::Request->new(
                stage         => $stage,
                method        => "listen",
                on_datagram   => "handle_datagram",
                on_recv_error => "handle_error",
                on_send_error => "handle_error",
                args          => {
                        bind_port   => 8675,
                },
        );

        # Echo the datagram back to its sender.
        sub handle_datagram :Handler {
                my ($rsp, $arg_remote_address, $arg_datagram);
                $rsp->recall(
                        method            => "send",
                        args              => {
                                remote_address  => $arg_remote_address,
                                datagram        => $arg_datagram,
                        },
                );
        }

DESCRIPTION ^

POE::Stage::Receiver is a simple UDP receiver/sender stage. It's simple, partly because it's incomplete.

POE::Stage::Receiver has two public methods: listen() and send(). It emits a small number of message types: datagram, recv_error, and send_error.

PUBLIC COMMANDS ^

Commands are invoked with POE::Request objects.

listen bind_port => INTEGER

Bind to a port on all local interfaces and begin listening for datagrams. Per the SYNOPSIS, the listen request should also map POE::Stage::Receiver's message types to appropriate handlers.

send datagram => SCALAR, remote_address => ADDRESS

Send a datagram to a remote address. Usually called via recall() to respond to a datagram emitted by the Receiver.

PUBLIC RESPONSES ^

Here's what POE::Stage::Resolver will send back.

"datagram" (datagram, remote_address)

POE::Stage::Receiver emits a "datagram" message whenever it successfully recv()s a datagram from some remote peer. The datagram message includes two parameters: "datagram" contains the received data, and "remote_address" contains the address that sent the datagram.

Both parameters can be passed back to the POE::Stage::Receiver's send() method, as is done in the SYNOPSIS.

        sub on_datagram {
                my ($arg_datagram, $arg_remote_address);
                my $output = function_of($arg_datagram);
                my $req->recall(
                        method => "send",
                        args => {
                                remote_address => $arg_remote_address,
                                datagram => $output,
                        }
                );
        }

"recv_error" (errnum, errstr)

The stage encountered an error receiving from a peer. "errnum" is the numeric form of $! after recv() failed. "errstr" is the error's string form.

        sub on_recv_error {
                goto &on_send_error;
        }

"send_error" (errnum, errstr)

The stage encountered an error receiving from a peer. "errnum" is the numeric form of $! after send() failed. "errstr" is the error's string form.

        sub on_send_error {
                my ($arg_errnum, $arg_errstr);
                warn "Error $arg_errnum : $arg_errstr.  Shutting down.\n";
                my $req_receiver = undef;
        }

BUGS ^

See http://thirdlobe.com/projects/poe-stage/report/1 for known issues. See http://thirdlobe.com/projects/poe-stage/newticket to report one.

POE::Stage is too young for production use. For example, its syntax is still changing. You probably know what you don't like, or what you need that isn't included, so consider fixing or adding that, or at least discussing it with the people on POE's mailing list or IRC channel. Your feedback and contributions will bring POE::Stage closer to usability. We appreciate it.

SEE ALSO ^

POE::Stage and POE::Request. The examples/udp-peer.perl program in POE::Stage's distribution.

AUTHORS ^

Rocco Caputo <rcaputo@cpan.org>.

LICENSE ^

POE::Stage::Receiver is Copyright 2005-2006 by Rocco Caputo. All rights are reserved. You may use, modify, and/or distribute this module under the same terms as Perl itself.

syntax highlighting: