public class SppClientSocket extends Object
To use this class, you must use DataListenSocket to create an SppServerSocket.
When a new connection is accepted by the server, SppServerSocket#accept returns a new
SppClientSocket to manage the data link.
On the client, you can use SppClientSocket to start a new socket connection.
| 限定符和类型 | 字段 | 说明 |
|---|---|---|
static int |
RFCOMM_SOCKET |
Indicates the RFCOMM socket connection.
|
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
void |
close() |
Disables a connection and releases related resources.
|
void |
connect() |
Connects to a remote device over the socket.
|
int |
getSppClientConnectionType() |
Obtains the connection type of a socket.
|
InputStream |
getSppClientInputStream() |
Obtains the input stream of a socket.
|
OutputStream |
getSppClientOutputStream() |
Obtains the output stream of a socket.
|
boolean |
isSppClientConnected() |
Obtains the connection status of a socket.
|
public static final int RFCOMM_SOCKET
public void connect()
throws IOException
When this method is called, the link will be blocked until the connection is established or fails.
It is not recommended that you initiate an SPP connection during device discovery,
which occupies many chip resources and slows down the connection.
You can use BluetoothHost#cancelBtDiscovery() to cancel the device discovery operation.
close() can be used to disable the connection.
IOException - Throws this exception if an error occurs, for example, a connection failure.public void close()
throws IOException
If the connection has been disabled, calling this method triggers no operation.
IOException - Throws this exception if the SppClientSocket fails to be disabled.public int getSppClientConnectionType()
RFCOMM_SOCKET.public InputStream getSppClientInputStream()
The input stream will be returned even if the socket is disconnected.
public OutputStream getSppClientOutputStream()
The output stream will be returned even if the socket is disconnected.
public boolean isSppClientConnected()
true if the socket is connected; returns false otherwise.