// 32feet.NET - Personal Area Networking for .NET
//
// InTheHand.Net.Bluetooth.BluetoothClient
//
// Copyright (c) 2003-2022 In The Hand Ltd, All rights reserved.
// This source code is licensed under the MIT License
using InTheHand.Net.Bluetooth;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Net.Sockets;
namespace InTheHand.Net.Sockets
{
///
/// Provides client connections for Bluetooth Rfcomm network services.
///
public sealed partial class BluetoothClient : IDisposable
{
public BluetoothClient()
{
PlatformInitialize();
}
///
/// Returns a collection of paired devices.
///
public IEnumerable PairedDevices
{
get
{
return GetPairedDevices();
}
}
///
/// Discovers accessible Bluetooth devices, and returns their names and addresses.
///
/// A collection of BluetoothDeviceInfo objects describing the devices discovered.
public IReadOnlyCollection DiscoverDevices()
{
return DiscoverDevices(255);
}
///
/// Discovers accessible Bluetooth devices, and returns their names and addresses.
///
/// A collection of BluetoothDeviceInfo objects describing the devices discovered.
public IReadOnlyCollection DiscoverDevices(int maxDevices)
{
return PlatformDiscoverDevices(maxDevices);
}
///
/// Connects the client to a remote Bluetooth host using the specified Bluetooth address and service identifier.
///
/// The BluetoothAddress of the remote host.
/// The Service Class Id of the service on the remote host.
/// The standard Bluetooth service classes are provided on .
public void Connect(BluetoothAddress address, Guid service)
{
PlatformConnect(address, service);
}
///
/// Closes the BluetoothClient and the underlying connection.
///
/// The Close method marks the instance as disposed and requests that the associated Socket close the Bluetooth connection
public void Close()
{
PlatformClose();
}
///
/// Sets whether an authenticated connection is required.
///
public bool Authenticate
{
get => GetAuthenticate();
set => SetAuthenticate(value);
}
///
/// Gets the underlying Socket.
///
public Socket Client
{
get => GetClient();
}
///
/// Gets a value indicating whether the underlying Socket for a BluetoothClient is connected to a remote host.
///
public bool Connected
{
get => GetConnected();
}
///
/// Sets whether an encrypted connection is required.
///
public bool Encrypt
{
get => GetEncrypt();
set => SetEncrypt(value);
}
///
/// Amount of time allowed to perform the query.
///
/// On Windows the actual value used is expressed in units of 1.28 seconds, so will be the nearest match for the value supplied.
/// The default value is 10 seconds. The maximum is 61 seconds.
public TimeSpan InquiryLength
{
[DebuggerStepThrough]
get { return GetInquiryLength(); }
[DebuggerStepThrough]
set { SetInquiryLength(value); }
}
///
/// Gets the name of the remote device.
///
public string RemoteMachineName
{
get
{
return GetRemoteMachineName();
}
}
///
/// Gets the underlying stream of data.
///
///
public NetworkStream GetStream()
{
return PlatformGetStream();
}
///
/// Closes the BluetoothClient and the underlying connection.
///
public void Dispose()
{
// Do not change this code. Put cleanup code in Dispose(bool disposing) above.
Dispose(true);
}
}
}