Author image PortaOne, Inc.
and 2 contributors


AnyEvent::Radius::Client - module to implement AnyEvent based RADIUS client


    use AnyEvent;
    use AnyEvent::Radius::Client;

    my $dict = AnyEvent::Radius::Client->load_dictionary('path-to-radius-dictionary');

    sub read_reply_callback {
        # $h is HASH-REF {type, request_id, av_list, from, authenticator}
        my ($self, $h) = @_;

    my $client = AnyEvent::Radius::Client->new(
                        ip => $ip,
                        port => $port,
                        on_read => \&read_reply_callback,
                        dictionary => $dict,
                        secret => $secret,


The AnyEvent::Radius::Client module allows to send multiple RADIUS requests in non-blocking way, and then wait for responses.


new ( ..options hash )
port - where to connect
secret - RADIUS secret string for remote server
dictionary - optional, dictionary loaded by load_dictionary() method
write_timeout - network I/O timeouts (default is 5 second)
on_read - called when reply received, arguments is hash-ref with {request_id, type, av_list, authenticator} keys
on_read_raw - called when reply received, raw data packet is provided as argument
on_read_timeout - timeout waiting for reply from server. Aborts the waiting state
on_write_timeout - timeout sending request
on_error - invalid packet received, or low-level socket error


load_dictionary ($dictionary-file)

Class method to load dictionary - returns the object to be passed to constructor

send_packet ( $type, $av_list, $cb )

Builds RADIUS packet using Data::Radius::Packet and store it to outgoing queue.

The type can be either the direct RFC packet type id, or one of its aliases, like COA, DM, POD, ACCT, AUTH ... see Data::Radius::Constants

Passing the optional callback $cb to be called upon receiving response to this request in form

  $cb->($resp_type, $resp_av_list)

or with empty parameters in case of missing response - eg. being timed out or unmatched authenticator


Returns request id. Note that it's not possible to schedule more than 255 requests - trying to add more will return undef

send_auth ($av_list, $cb)
send_acct ($av_list, $cb)
send_pod ($av_list, $cb)
send_coa ($av_list, $cb)

Alias methods to send RADIUS request of required type by send_packet()


Blocks until all requests are received or read timeout reached

on_ready ( $cond_var )

Used to coordinate multiple clients instead of wait()


    my $cv = AnyEvent->condvar;

Will be blocked until all clients finish their queue.


Destroy the internal socket handle. Must be called when object is no longer required. When called from callback, it is recommended to wrap this call into AnyEvent::postpone { ... } block.


Authen::Radius, AnyEvent::Radius::Server, Data::Radius


Sergey Leschenko < at>

PortaOne Development Team <perl-radius at> is the current module's maintainer at CPAN.