Android.Bluetooth.BluetoothSocket Class
A connected or connecting Bluetooth socket.

See Also: BluetoothSocket Members

Syntax

[Android.Runtime.Register("android/bluetooth/BluetoothSocket", DoNotGenerateAcw=true)]
public sealed class BluetoothSocket : Java.Lang.Object, Java.IO.ICloseable, IDisposable

Remarks

A connected or connecting Bluetooth socket.

The interface for Bluetooth Sockets is similar to that of TCP sockets: Java.Net.Socket and Java.Net.ServerSocket. On the server side, use a Android.Bluetooth.BluetoothServerSocket to create a listening server socket. When a connection is accepted by the Android.Bluetooth.BluetoothServerSocket, it will return a new Android.Bluetooth.BluetoothSocket to manage the connection. On the client side, use a single Android.Bluetooth.BluetoothSocket to both initiate an outgoing connection and to manage the connection.

The most common type of Bluetooth socket is RFCOMM, which is the type supported by the Android APIs. RFCOMM is a connection-oriented, streaming transport over Bluetooth. It is also known as the Serial Port Profile (SPP).

To create a Android.Bluetooth.BluetoothSocket for connecting to a known device, use BluetoothDevice.CreateRfcommSocketToServiceRecord(Java.Util.UUID). Then call BluetoothSocket.Connect to attempt a connection to the remote device. This call will block until a connection is established or the connection fails.

To create a Android.Bluetooth.BluetoothSocket as a server (or "host"), see the Android.Bluetooth.BluetoothServerSocket documentation.

Once the socket is connected, whether initiated as a client or accepted as a server, open the IO streams by calling BluetoothSocket.InputStream and BluetoothSocket.OutputStream in order to retrieve Java.IO.InputStream and Java.IO.OutputStream objects, respectively, which are automatically connected to the socket.

Android.Bluetooth.BluetoothSocket is thread safe. In particular, BluetoothSocket.Close will always immediately abort ongoing operations and close the socket.

Note: Requires the NoType:android/Manifest$permission;Href=../../../reference/android/Manifest.permission.html#BLUETOOTH permission.

Developer Guides

For more information about using Bluetooth, read the Bluetooth developer guide.

See Also

[Android Documentation]

Requirements

Namespace: Android.Bluetooth
Assembly: Mono.Android (in Mono.Android.dll)
Assembly Versions: 0.0.0.0
Since: Added in API level 5