View on
Cal Henderson > FUSE-Server-1.19 > FUSE::Server



Annotate this POD

View/Report Bugs
Module Version: 1.19   Source  


FUSE::Server - Perl-FUSE server


  use FUSE::Server;
  my $s = FUSE::Server->new({

  my $status = $s->bind();
  print "Server started: $status";




  $SIG{INT} = $SIG{TERM} = $SIG{HUP} = sub{$s->stop();};


  sub msg_broadcast{
      my ($userid,$msg,$params) = @_;
      my @a = split /\//,$params;

  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:

$s = FUSE::Server->new( [%options] );

The object constructor takes the following arguments in the options hash:

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.


This method starts the server listening on it's port and returns the IP which it is listening on.

$s->addCallback( $message, $coderef );

This method registers the referenced subroutine as a handler for the specified message. When the server receives that message from the client, it checks it's handler hash and dispatches the decoded message to the sub. The sub should handle the following arguments:

( $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:


This message is sent when a client first connects. It is typically used to issue a SECRET_KEY message to the client.


This message is sent when a client disconnects.

$s->defaultCallback( $coderef );

For all messages without an assigned handler, the default handler (if set) is sent the message. If you'd like to handle all messages internally, then setup defaultCallback without setting up any normal addCallback's.


This method shuts down the server gracefully. Since the start method loops forever, the stop method is generally set up to run on a signal.


This method invokes the server's internal message pump. This loop can only be broken by a signal.

$s->send( $userid, $message, $params );

This method sends a message to a single client.

$s->sendAll( $message, $params );

This method broadcasts a message to all clients.


Cal Henderson, <>

syntax highlighting: