Graham Ollis > AnyEvent-Finger > AnyEvent::Finger::Server



Annotate this POD


View/Report Bugs
Module Version: 0.09   Source  


AnyEvent::Finger::Server - Simple asynchronous finger server


version 0.09


 use AnyEvent::Finger::Server;
 my $server = AnyEvent::Finger::Server->new;
 my %users = (
   grimlock => "ME GRIMLOCK HAVE PLAN",
   optimus  => "Freedom is the right of all sentient beings.",
 $server->start(sub {
   my($tx) = @_;
     # respond if remote requests list of users
     $tx->res->say('users:', keys %users);
     # respond if user exists
     if(defined $users{$tx->req->username})
     # respond if user does not exist
       $tx->res->say('no such user');
   # required! done generating the reply,
   # close the connection with the client.


Provide a simple asynchronous finger server.


The constructor takes the following optional arguments:


$server->start( $callback )

Start the finger server. The callback will be called each time a client connects.


The first argument passed to the callback is the transaction object, which is an instance of AnyEvent::Finger::Transaction. The most important members of these objects that you will want to interact with are $tx->req for the request (an instance of AnyEvent::Finger::Request) and $tx->res for the response interface (an instance of AnyEvent::Finger::Response).

With the response object you can return a whole response at one time:

   "this is the first line", 
   "this is the second line", 
   "there will be no forth line",

or you can send line one at a time as they become available (possibly asynchronously).

 # $dbh is a DBI database handle
 my $sth = $dbh->prepare("select user_name from user_list");
 while(my $h = $sth->fetchrow_hashref)

The server will unbind from its port and stop if the server object falls out of scope, or if the stop method (see below) is called.


The bind port. If port is set to zero in the constructor or on start, then an ephemeral port will be used, and you can get the port number here. This value is not available until the socket has been allocated and bound to a port, so if you need this value after calling start but before any clients have connected use the on_bind callback.


Stop the server and unbind to the port.


Graham Ollis <>


This software is copyright (c) 2012 by Graham Ollis.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

syntax highlighting: