|
FUSE::Server - Perl-FUSE server |
FUSE::Server - Perl-FUSE server
use FUSE::Server;
my $s = FUSE::Server->new({
Port=>35008,
MaxClients=>5000,
Quiet=>1,
});
my $status = $s->bind(); print "Server started: $status";
$s->addCallback('BROADCASTALL',\&msg_broadcast);
$s->addCallback('client_start',\&msg_client_start);
$s->defaultCallback(\&unknown_command);
$SIG{INT} = $SIG{TERM} = $SIG{HUP} = sub{$s->stop();};
$s->start();
sub msg_broadcast{
my ($userid,$msg,$params) = @_;
my @a = split /\//,$params;
$s->sendAll($a[1],$a[2]);
}
sub msg_client_start{
my ($userid,$msg,$params) = @_;
$s->send($userid,'SECRET_KEY','123 456 789');
}
sub unknown_command{
my ($userid,$msg,$params) = @_;
print "Unknown command $msg\n";
}
The FUSE::Server module will create a TCP FUSE server and dispatch messages to registered event handlers.
The external interface to FUSE::Server is:
Quiet = 0|1
Whether to be quiet. Default is to report all events to STDOUT (not 'Quiet').
Port = n
The port for the server to listen on. Default is 1024.
MaxClients = n
Maximum incoming connections to allow. Default is SOMAXCONN.
( $userid, $msg, $params )
$userid contains the internal connection id for the client session. You can use this id to associate logins with clients. The $msg parameter contains the message the client sent. This allows one routine to handle more than one message. Messages from clients are typically uppercase, with lowercase messages being reserved for internal server events, such as client connect/disconnect. The available internal messages are:
client_start
This message is sent when a client first connects. It is typically used to issue a SECRET_KEY message to the client.
client_stop
This message is sent when a client disconnects.
defaultCallback without setting up any normal addCallback's.
start method loops forever, the stop method is generally set up to run on a signal.
Cal Henderson, <cal@iamcal.com>
|
FUSE::Server - Perl-FUSE server |