DataLife Engine > Programming > Net::Bluetooth 0.40 - Интерфейс Блютуз

Net::Bluetooth 0.40 - Интерфейс Блютуз


17 мая 2008. Разместил: mafiozzzza
Net::Bluetooth 0.40 - Интерфейс Блютуз  Net::Bluetooth - Интерфейс блютуз на Perl.
  
0.016 MB|License: Perl Artistic License

Net::Bluetooth is a Perl bluetooth interface.

SYNOPSIS

use Net::Bluetooth;

#### list all remote devices in the area
my $device_ref = get_remote_devices();
foreach $addr (keys %$device_ref) {
print "Address: $addr Name: $device_ref->{$addr}n";
}


#### search for a specific service (0x1101) on a remote device
my @sdp_array = sdp_search($addr, "1101", "");

#### foreach service record
foreach $rec_ref (@sdp_array) {
#### Print all available information for service
foreach $attr (keys %$rec_ref) {
print "Attribute: $attr Value: $rec_ref->{$attr}n";
}
}


#### Create a RFCOMM client
$obj = Net::Bluetooth->newsocket("RFCOMM");
die "socket error $!n" unless(defined($obj));
if($obj->connect($addr, $port) != 0) {
die "connect error: $!n";
}

#### create a Perl filehandle for reading and writing
*SERVER = $obj->perlfh();
$amount = read(SERVER, $buf, 256);
close(SERVER);



#### create a RFCOMM server
$obj = Net::Bluetooth->newsocket("RFCOMM");
#### bind to port 1
if($obj->bind(1) != 0) {
die "bind error: $!n";
}

#### listen with a backlog of 2
if($obj->listen(2) != 0) {
die "listen error: $!n";
}

#### register a service
#### $obj must be a open and bound socket
my $service_obj = Net::Bluetooth->newservice($obj, "1101", "GPS", "GPS Receiver");
unless(defined($service_obj)) {
#### couldn't register service
}

#### accept a client connection
$client_obj = $obj->accept();
unless(defined($client_obj)) {
die "client accept failed: $!n";
}

#### get client information
my ($caddr, $port) = $client_obj->getpeername();

#### create a Perl filehandle for reading and writing
*CLIENT = $client_obj->perlfh();
print CLIENT "stuff";

#### close client connection
close(CLIENT);
#### stop advertising service
$service_obj->stopservice();
#### close server connection
$obj->close();

Requirements:

· Perl


Net::Bluetooth 0.40 - Интерфейс Блютуз