Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

45 lines (35 sloc) 0.849 kb
#!/usr/bin/env perl
use warnings;
use strict;
use lib qw(../lib);
# An object's emitted events can also trigger methods in the subclass.
# This example creates a UDP echo server using a role rather than
# inheritance.
{
package Reflex::UdpPeer::Echo;
use Moose;
with 'Reflex::Role::UdpPeer';
sub on_my_datagram {
my ($self, $args) = @_;
my $data = $args->{datagram};
if ($data =~ /^\s*shutdown\s*$/) {
$self->destruct();
return;
}
$self->send(
datagram => $data,
remote_addr => $args->{remote_addr},
);
}
sub on_my_error {
my ($self, $args) = @_;
warn "$args->{op} error $args->{errnum}: $args->{errstr}";
$self->destruct();
}
}
# Main.
my $port = 12345;
my $peer = Reflex::UdpPeer::Echo->new( port => $port );
print "UDP echo service is listening on port $port.\n";
Reflex::Object->run_all();
exit;
Jump to Line
Something went wrong with that request. Please try again.