Net::OpenSoundControl::Client - OpenSound Control client implementation


Net-OpenSoundControl documentation Contained in the Net-OpenSoundControl distribution.

Index


Code Index:

NAME

Top

Net::OpenSoundControl::Client - OpenSound Control client implementation

SYNOPSIS

Top

  use Net::OpenSoundControl::Client;

  my $client = Net::OpenSoundControl::Client->new(
      Host => "192.168.3.240", Port => 7777)
      or die "Could not start client: $@\n";

  # This is a very slow fade-in...
  for (0..100) {
      $client->send(['/Main/Volume', 'f', $_ / 100]);
      sleep(1);
  }

DESCRIPTION

Top

This module implements an OSC client sending messages via UDP.

METHODS

Top

new(Host => Host, Port => $port, Name => $name)

Creates a new client object. The default host is localhost, the default port 7123 and the default name Net-OpenSoundControl-Client talking to localhost:7123.

Returns undef on failure (in this case, $@ is set).

name()

Returns the name of the client

host()

Returns the server host we are talking to

port()

Returns the server port we are talking to

send($data)

Sends an OSC message or bundle to the server

SEE ALSO

Top

The OpenSound Control website: http://www.cnmat.berkeley.edu/OpenSoundControl/

Net::OpenSoundControl

AUTHOR

Top

Christian Renz, <crenz @ web42.com>

COPYRIGHT AND LICENSE

Top


Net-OpenSoundControl documentation Contained in the Net-OpenSoundControl distribution.
package Net::OpenSoundControl::Client;

use 5.006;
use strict;
use warnings;
use IO::Socket;
use Net::OpenSoundControl;

our @ISA = qw();

our $VERSION = '0.02';

sub new {
    my $class = shift;
    my %opts  = @_;
    my $self  = {};

    $self->{HOST} = $opts{Host} || "localhost";
    $self->{PORT} = $opts{Port} || 7123;
    $self->{NAME} = $opts{Name}
      || 'Net-OpenSoundControl-Client talking to ' . $self->{HOST} . ':' .
      $self->{PORT};

    $self->{SOCKET} = IO::Socket::INET->new(
        PeerAddr => $self->{HOST},
        PeerPort => $self->{PORT},
        Proto    => 'udp')
      or return undef;    # error is in $@

    bless $self, $class;
}

sub name {
    my $self = shift;

    return $self->{NAME};
}

sub host {
    my $self = shift;

    return $self->{HOST};
}

sub port {
    my $self = shift;

    return $self->{PORT};
}

sub send {
    my $self = shift;
    my ($data) = @_;

    $self->{SOCKET}->send(Net::OpenSoundControl::encode($data));
}

1;