# Print output for @column tags ?>
Developers

- Design
- Develop
- Distribute

Developer Console

## Most visited

## Recently visited

## Results for

Summary: Methods | Inherited Methods

# BluetoothServerSocket

`public final class BluetoothServerSocket`
`extends Object` `implements Closeable`

java.lang.Object
↳ | android.bluetooth.BluetoothServerSocket

A listening Bluetooth socket.

The interface for Bluetooth Sockets is similar to that of TCP sockets: `Socket` and `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()`.

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()` 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 not close the returned `BluetoothSocket`.

`BluetoothServerSocket` is thread safe. In particular, `close()` will always immediately abort ongoing operations and close the server socket.

### Developer Guides

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

See also:

- `BluetoothSocket`

## Summary

### Public methods
`BluetoothSocket` | `accept()` Block until a connection is established.
`BluetoothSocket` | `accept(int timeout)` Block until a connection is established, with timeout.
`void` | `close()` Immediately close this socket, and release all associated resources.
`int` | `getPsm()` Returns the assigned dynamic protocol/service multiplexer (PSM) value for the listening L2CAP Connection-oriented Channel (CoC) server socket.
`String` | `toString()` Returns a string representation of the object.

### Inherited methods
From class `java.lang.Object`
`Object` | `clone()` Creates and returns a copy of this object.
`boolean` | `equals(Object obj)` Indicates whether some other object is "equal to" this one.
`void` | `finalize()` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
`final Class<?>` | `getClass()` Returns the runtime class of this `Object`.
`int` | `hashCode()` Returns a hash code value for the object.
`final void` | `notify()` Wakes up a single thread that is waiting on this object's monitor.
`final void` | `notifyAll()` Wakes up all threads that are waiting on this object's monitor.
`String` | `toString()` Returns a string representation of the object.
`final void` | `wait(long timeout, int nanos)` Causes the current thread to wait until another thread invokes the `notify()` method or the `notifyAll()` method for this object, or some other thread interrupts the current thread, or a certain amount of real time has elapsed.
`final void` | `wait(long timeout)` Causes the current thread to wait until either another thread invokes the `notify()` method or the `notifyAll()` method for this object, or a specified amount of time has elapsed.
`final void` | `wait()` Causes the current thread to wait until another thread invokes the `notify()` method or the `notifyAll()` method for this object.
From interface `java.io.Closeable`
`abstract void` | `close()` Closes this stream and releases any system resources associated with it.
From interface `java.lang.AutoCloseable`
`abstract void` | `close()` Closes this resource, relinquishing any underlying resources.

## Public methods

### accept

    public BluetoothSocket accept ()

Block until a connection is established.

Returns a connected `BluetoothSocket` on successful connection.

Once this call returns, it can be called again to accept subsequent incoming connections.

`close()` can be used to abort this call from another thread.

Returns
`BluetoothSocket` | a connected `BluetoothSocket`

Throws
`IOException` | on error, for example this call was aborted, or timeout

### accept

    public BluetoothSocket accept (int timeout)

Block until a connection is established, with timeout.

Returns a connected `BluetoothSocket` on successful connection.

Once this call returns, it can be called again to accept subsequent incoming connections.

`close()` can be used to abort this call from another thread.

Parameters
`timeout` | `int`

Returns
`BluetoothSocket` | a connected `BluetoothSocket`

Throws
`IOException` | on error, for example this call was aborted, or timeout

### close

    public void close ()

Immediately close this socket, and release all associated resources.

Causes blocked calls on this socket in other threads to immediately throw an IOException.

Closing the `BluetoothServerSocket` will not close any `BluetoothSocket` received from `accept()`.

Throws
`IOException` |

### getPsm

    public int getPsm ()

Returns the assigned dynamic protocol/service multiplexer (PSM) value for the listening L2CAP Connection-oriented Channel (CoC) server socket. This server socket must be returned by the `BluetoothAdapter#listenUsingL2capChannel()` or `BluetoothAdapter.listenUsingInsecureL2capChannel()`. The returned value is undefined if this method is called on non-L2CAP server sockets.

Returns
`int` | the assigned PSM or LE_PSM value depending on transport

### toString

    public String toString ()

Returns a string representation of the object. In general, the `toString` method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.

The `toString` method for class `Object` returns a string consisting of the name of the class of which the object is an instance, the at-sign character ``@`', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:

>      getClass().getName() + '@' + Integer.toHexString(hashCode())

Returns
`String` | a string representation of the object.

Full name *
Email address *
Company / developer name
One of your Play Store app URLs *
Which best describes your business:*
Apps
Games
Apps & Games
*
*