BluetoothServerSocket Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
A listening Bluetooth socket.
[Android.Runtime.Register("android/bluetooth/BluetoothServerSocket", DoNotGenerateAcw=true)]
public sealed class BluetoothServerSocket : Java.Lang.Object, IDisposable, Java.Interop.IJavaPeerable, Java.IO.ICloseable
[<Android.Runtime.Register("android/bluetooth/BluetoothServerSocket", DoNotGenerateAcw=true)>]
type BluetoothServerSocket = class
inherit Object
interface ICloseable
interface IJavaObject
interface IDisposable
interface IJavaPeerable
- Inheritance
- Attributes
- Implements
Remarks
A listening 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 BluetoothServerSocket
to create a listening server socket. When a connection is accepted by the BluetoothServerSocket
, it will return a new BluetoothSocket
to manage the connection. On the client side, use a single BluetoothSocket
to both initiate an outgoing connection and to manage the connection.
For Bluetooth BR/EDR, the most common type of socket is RFCOMM, which is the type supported by the Android APIs. RFCOMM is a connection-oriented, streaming transport over Bluetooth BR/EDR. It is also known as the Serial Port Profile (SPP). To create a listening BluetoothServerSocket
that's ready for incoming Bluetooth BR/EDR connections, use BluetoothAdapter#listenUsingRfcommWithServiceRecord BluetoothAdapter.listenUsingRfcommWithServiceRecord()
.
For Bluetooth LE, the socket uses LE Connection-oriented Channel (CoC). LE CoC is a connection-oriented, streaming transport over Bluetooth LE and has a credit-based flow control. Correspondingly, use BluetoothAdapter#listenUsingL2capChannel BluetoothAdapter.listenUsingL2capChannel()
to create a listening BluetoothServerSocket
that's ready for incoming Bluetooth LE CoC connections. For LE CoC, you can use #getPsm()
to get the protocol/service multiplexer (PSM) value that the peer needs to use to connect to your socket.
After the listening BluetoothServerSocket
is created, call #accept()
to listen for incoming connection requests. This call will block until a connection is established, at which point, it will return a BluetoothSocket
to manage the connection. Once the BluetoothSocket
is acquired, it's a good idea to call #close()
on the BluetoothServerSocket
when it's no longer needed for accepting connections. Closing the BluetoothServerSocket
will <em>not</em> close the returned BluetoothSocket
.
BluetoothServerSocket
is thread safe. In particular, #close
will always immediately abort ongoing operations and close the server socket.
<div class="special reference">
<h3>Developer Guides</h3>
For more information about using Bluetooth, read the Bluetooth developer guide. </div>
Java documentation for android.bluetooth.BluetoothServerSocket
.
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.
Properties
Class |
Returns the runtime class of this |
Handle |
The handle to the underlying Android instance. (Inherited from Object) |
JniIdentityHashCode | (Inherited from Object) |
JniPeerMembers | |
PeerReference | (Inherited from Object) |
Psm |
Returns the assigned dynamic protocol/service multiplexer (PSM) value for the listening L2CAP Connection-oriented Channel (CoC) server socket. |
ThresholdClass |
This API supports the Mono for Android infrastructure and is not intended to be used directly from your code. (Inherited from Object) |
ThresholdType |
This API supports the Mono for Android infrastructure and is not intended to be used directly from your code. (Inherited from Object) |
Methods
Accept() |
Block until a connection is established. |
Accept(Int32) |
Block until a connection is established, with timeout. |
AcceptAsync() | |
AcceptAsync(Int32) | |
Clone() |
Creates and returns a copy of this object. (Inherited from Object) |
Close() |
Immediately close this socket, and release all associated resources. |
Dispose() | (Inherited from Object) |
Dispose(Boolean) | (Inherited from Object) |
Equals(Object) |
Indicates whether some other object is "equal to" this one. (Inherited from Object) |
GetHashCode() |
Returns a hash code value for the object. (Inherited from Object) |
JavaFinalize() |
Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. (Inherited from Object) |
Notify() |
Wakes up a single thread that is waiting on this object's monitor. (Inherited from Object) |
NotifyAll() |
Wakes up all threads that are waiting on this object's monitor. (Inherited from Object) |
SetHandle(IntPtr, JniHandleOwnership) |
Sets the Handle property. (Inherited from Object) |
ToArray<T>() | (Inherited from Object) |
ToString() |
Returns a string representation of the object. (Inherited from Object) |
UnregisterFromRuntime() | (Inherited from Object) |
Wait() |
Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>. (Inherited from Object) |
Wait(Int64, Int32) |
Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed. (Inherited from Object) |
Wait(Int64) |
Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed. (Inherited from Object) |
Explicit Interface Implementations
IJavaPeerable.Disposed() | (Inherited from Object) |
IJavaPeerable.DisposeUnlessReferenced() | (Inherited from Object) |
IJavaPeerable.Finalized() | (Inherited from Object) |
IJavaPeerable.JniManagedPeerState | (Inherited from Object) |
IJavaPeerable.SetJniIdentityHashCode(Int32) | (Inherited from Object) |
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) | (Inherited from Object) |
IJavaPeerable.SetPeerReference(JniObjectReference) | (Inherited from Object) |
Extension Methods
JavaCast<TResult>(IJavaObject) |
Performs an Android runtime-checked type conversion. |
JavaCast<TResult>(IJavaObject) | |
GetJniTypeName(IJavaPeerable) |
Gets the JNI name of the type of the instance |
JavaAs<TResult>(IJavaPeerable) |
Try to coerce |
TryJavaCast<TResult>(IJavaPeerable, TResult) |
Try to coerce |