GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
POE::Stage::Receiver(3) User Contributed Perl Documentation POE::Stage::Receiver(3)

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

        # 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,
                        },
                );
        }

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.

Commands are invoked with POE::Request objects.

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 a datagram to a remote address. Usually called via recall() to respond to a datagram emitted by the Receiver.

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

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,
                        }
                );
        }

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;
        }

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;
        }

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.

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

Rocco Caputo <rcaputo@cpan.org>.

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.
2006-12-25 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.