/usr/share/doc/libanyevent-handle-udp-perl/examples/anyevent-udp-server.pl is in libanyevent-handle-udp-perl 0.042-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | #!/usr/bin/env perl
=head1 NAME
anyevent-udp-server.pl - Simple AnyEvent::Handle::UDP UDP server
=head1 DESCRIPTION
Starts a UDP server that listens on a given port for
input (incoming udp packets).
To test it, you can use the following command:
$ echo "Test1" | nc -u -q1 localhost 4000
=head1 AUTHOR
Cosimo Streppone
=cut
use strict;
use warnings;
use AnyEvent::Handle::UDP;
use AnyEvent::Log ();
# Default for AnyEvent is to log nothing
$AnyEvent::Log::FILTER->level('debug');
# AE::Handle::UDP does all for us:
# be sure to use the "bind" option!
my $udp_server = AnyEvent::Handle::UDP->new(
# Bind to this host and port
bind => ['0.0.0.0', 4000],
# AnyEvent will run this callback when getting some input
on_recv => sub {
my ($data, $ae_handle, $client_addr) = @_;
chomp $data;
AE::log warn => "Received '$data' (handle: $ae_handle)";
# Send back the command echoed to the client who contacted us
$ae_handle->push_send("echo [$data]\n", $client_addr);
}
);
# Start the main event loop
my $condvar = AE::cv;
$condvar->recv;
# Never gets here.
|