Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

62 lines (49 sloc) 1.077 kB
#!/usr/bin/env perl
# vim: ts=2 sw=2 noexpandtab
use warnings;
use strict;
use lib qw(../lib);
# This example creates a UDP echo server using a role rather than
# inheritance.
{
package Reflex::Udp::Echo;
use Moose;
extends 'Reflex::Base';
use IO::Socket::INET;
use Reflex::Callbacks qw(make_error_handler);
has socket => (
is => 'ro',
isa => 'FileHandle',
required => 1,
);
has active => (
is => 'ro',
isa => 'Bool',
default => 1,
);
make_error_handler("on_socket_error");
with 'Reflex::Role::Recving' => {
att_handle => 'socket',
att_active => 'active',
method_send => 'send',
};
sub on_socket_datagram {
my ($self, $datagram) = @_;
if ($datagram->octets() =~ /^\s*shutdown\s*$/) {
$self->stop_socket_readable();
return;
}
$self->send($datagram->_body());
}
}
# Main.
my $port = 12345;
my $peer = Reflex::Udp::Echo->new(
socket => IO::Socket::INET->new(
LocalPort => $port,
Proto => 'udp',
)
);
print "UDP echo service is listening on port $port.\n";
Reflex->run_all();
exit;
Jump to Line
Something went wrong with that request. Please try again.