public class DataListenSocket extends Object
This class provides four methods for creating a Bluetooth socket:
dataListenInsecureRfcomm(java.lang.String,java.util.UUID): creates an insecure RFCOMM Bluetooth server
listening socket based on service records.
dataListenRfcomm(java.lang.String,java.util.UUID): creates a secure RFCOMM Bluetooth server listening socket
based on service records.
buildInsecureRfcommDataSocket(ohos.bluetooth.BluetoothRemoteDevice,java.util.UUID):Creates an insecure RFCOMM Bluetooth
client socket based on the service record.
buildRfcommDataSocket(ohos.bluetooth.BluetoothRemoteDevice,java.util.UUID):Creates an secure RFCOMM Bluetooth client socket
based on the service record.| 限定符和类型 | 方法 | 说明 |
|---|---|---|
SppClientSocket |
buildInsecureRfcommDataSocket(BluetoothRemoteDevice device,
UUID uuid) |
Creates an insecure RFCOMM Bluetooth client socket based on the service record.
|
SppClientSocket |
buildRfcommDataSocket(BluetoothRemoteDevice device,
UUID uuid) |
Creates an secure RFCOMM Bluetooth client socket based on the service record.
|
SppServerSocket |
dataListenInsecureRfcomm(String name,
UUID uuid) |
Creates an insecure RFCOMM Bluetooth server listening socket based on the service record.
|
SppServerSocket |
dataListenRfcomm(String name,
UUID uuid) |
Creates a secure RFCOMM Bluetooth server listening socket based on the service record.
|
public SppServerSocket dataListenInsecureRfcomm(String name, UUID uuid) throws IOException
This connection mode does not require link key authentication and may encounter man-in-the-middle attacks.
For Bluetooth 2.1 devices, the link will be forcibly encrypted. For devices using earlier Bluetooth versions,
the link will not be encrypted. If you need an encrypted communication channel,
use dataListenRfcomm(java.lang.String, java.util.UUID).
Use SppServerSocket#accept to retrieve incoming connections from devices.
The system will assign an unused RFCOMM channel.
The system registers a Service Discovery Protocol (SDP) record with the local SDP server, records the service name, and automatically assigns a channel. Remote Bluetooth devices can use the same UUID to query the SDP server and identify the channel to connect to. This SDP record will be removed if the socket is disabled or the application exits unexpectedly.
name - Indicates the service name in the SDP record.uuid - Indicates the UUID in the SDP record.SppServerSocket.IOException - Throws this exception if an error occurs, for example, Bluetooth is disabled or unavailable.public SppServerSocket dataListenRfcomm(String name, UUID uuid) throws IOException
A remote device connecting to this socket is authenticated and communication over this socket is encrypted.
Use SppServerSocket#accept to retrieve incoming connections from devices.
The system will assign an unused RFCOMM channel.
The system registers a Service Discovery Protocol (SDP) record with the local SDP server, records the service name, and automatically assigns a channel. Remote Bluetooth devices can use the same UUID to query the SDP server and identify the channel to connect to. This SDP record will be removed if the socket is disabled or the application exits unexpectedly.
name - Indicates the service name in the SDP record.uuid - Indicates the UUID in the SDP record.SppServerSocket.IOException - Throws this exception if an error occurs, for example, Bluetooth is disabled or unavailable.public SppClientSocket buildInsecureRfcommDataSocket(BluetoothRemoteDevice device, UUID uuid) throws IOException
This connection mode does not require link key authentication and may encounter man-in-the-middle attacks.
For Bluetooth 2.1 devices, the link will be forcibly encrypted. For devices using earlier Bluetooth versions,
the link will not be encrypted. If you need an encrypted communication channel,
use buildRfcommDataSocket(ohos.bluetooth.BluetoothRemoteDevice, java.util.UUID).
Use SppClientSocket#connect to initiate the outgoing connection.
The system will assign an unused RFCOMM channel.
device - Indicates an bluetooth remote device.uuid - Indicates the UUID in the SDP record.SppClientSocket.IOException - Throws this exception if an error occurs, for example, Bluetooth is disabled or unavailable.public SppClientSocket buildRfcommDataSocket(BluetoothRemoteDevice device, UUID uuid) throws IOException
The remote device will be authenticated and communication on this socket will be encrypted.
Use SppClientSocket#connect to initiate the outgoing connection.
The system will assign an unused RFCOMM channel.
device - Indicates an bluetooth remote device.uuid - Indicates the UUID in the SDP record.SppClientSocket.IOException - Throws this exception if an error occurs, for example, Bluetooth is disabled or unavailable.