FUSE::Client - Perl-FUSE client


FUSE-Client documentation Contained in the FUSE-Client distribution.

Index


Code Index:

NAME

Top

FUSE::Client - Perl-FUSE client

SYNOPSIS

Top

  use FUSE::Client;
  $c = FUSE::Client->new({
      Port=>35008,
      Quiet=>1,
  });

  $c->connect();
  $c->send("COMMAND","parameter");
  $c->disconnect();

DESCRIPTION

Top

The FUSE::Client module will create a TCP FUSE client to test sending messages to a FUSE server.

The external interface to FUSE::Client is:

$c = FUSE::Client->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 client to connect to. Default is 1024.

$c->connect();

This method connects the client to the server.

$c->disconnect();

This method disconnects the client from the server.

$c->send( $command, $parameter );

Send a FUSE formatted command message to the server, with the specified parameter.

AUTHOR

Top

Cal Henderson, <cal@iamcal.com>


FUSE-Client documentation Contained in the FUSE-Client distribution.

package FUSE::Client;

require 5;
use strict;

use vars qw($VERSION @ISA @EXPORT);

use IO::Socket;

require Exporter;

@ISA = qw(Exporter);
@EXPORT = qw();
$VERSION = '1.08';

sub new {
	my ($class,$params) = @_;
	my $self = {};
	bless $self,ref $class || $class;
	$self->{quiet} = ${$params}{Quiet};
	$self->{port} = ${$params}{Port} || 1024;
	$self->{sock} = 0;
	return $self;
}

sub connect {
	my ($self,$host) = @_;
	$self->{sock} = new IO::Socket::INET ( PeerAddr => $host, PeerPort => $self->{port}, Proto => 'tcp' );
	$self->{sock}->autoflush(1);
	die "Could not create socket: $!\n" unless $self->{sock};
}

sub disconnect {
	my ($self) = @_;
	close($self->{sock});
}

sub send {
	my ($self,$msg,$params) = @_;

	$msg = "$msg $params";
	my $msg_frm = sprintf("%04d%s",length($msg),$msg);

	print "sending $msg_frm\n" unless $self->{Quiet};

	syswrite($self->{sock}, $msg_frm, length($msg_frm));
}


1;
__END__