Functions |
int | bt_socket_create_rfcomm (const char *service_uuid, int *socket_fd) |
| Registers a rfcomm server socket with a specific UUID.
|
int | bt_socket_destroy_rfcomm (int socket_fd) |
| Removes the rfcomm server socket which was created using bt_socket_create_rfcomm().
|
int | bt_socket_listen_and_accept_rfcomm (int socket_fd, int max_pending_connections) |
| Starts listening on passed rfcomm socket and accepts connection requests.
|
int | bt_socket_connect_rfcomm (const char *remote_address, const char *service_uuid) |
| Connects to a specific RFCOMM based service on a remote Bluetooth device UUID, asynchronously.
|
int | bt_socket_disconnect_rfcomm (int socket_fd) |
| Disconnects the RFCOMM connection with the given file descriptor of conneted socket.
|
int | bt_socket_send_data (int socket_fd, const char *data, int length) |
| Sends data to the connected device.
|
int | bt_socket_set_data_received_cb (bt_socket_data_received_cb callback, void *user_data) |
| Register a callback function that will be invoked when you receive data.
|
int | bt_socket_unset_data_received_cb (void) |
| Unregisters the callback function.
|
int | bt_socket_set_connection_requested_cb (bt_socket_connection_requested_cb callback, void *user_data) |
| Register a callback function that will be invoked when a RFCOMM connection is requested.
|
int | bt_socket_unset_connection_requested_cb (void) |
| Unregisters the callback function.
|
int | bt_socket_set_connection_state_changed_cb (bt_socket_connection_state_changed_cb callback, void *user_data) |
| Register a callback function that will be invoked when the connection state changes.
|
int | bt_socket_unset_connection_state_changed_cb (void) |
| Unregisters the callback function.
|
Typedefs |
typedef void(* | bt_socket_data_received_cb )(bt_socket_received_data_s *data, void *user_data) |
| Called when you receive data.
|
typedef void(* | bt_socket_connection_state_changed_cb )(int result, bt_socket_connection_state_e connection_state, bt_socket_connection_s *connection, void *user_data) |
| Called when the socket connection state changes.
|
Bluetooth Socket API provides functions for managing connections to other devices and exchanging data.
Required Header
#include <bluetooth.h>
Overview
This set of functions is used for exchanging data between two bluetooth devices, our device can have both roles as server (service provider) and client (service user). Depending on the role, there is difference in creating a connection. After that, processes of exchanging data and disconnection are same.
To start communication, you should first register for bt_socket_set_connection_state_changed_cb() and bt_socket_set_data_received_cb(). Next step depends on the role of your application.
If you want to be server role, application should create socket (bt_socket_create_rfcomm()), and start listening and accepting incoming connections (bt_socket_listen_and_accept_rfcomm()). If you want to connect to specific device and use it's services (client role), you have to start connection with bt_socket_connect_rfcomm() and wait for connection.
After connection has been established (information is passed to your program with bt_socket_connection_state_changed_cb() function call), you can exchange data by calling bt_socket_send_data().
If you receive data from remote device, bt_socket_data_received_cb() functions will be called. When you finish exchanging data, you should disconnect connection with bt_socket_disconnect_rfcomm() and unregister callback functions (with using bt_socket_unset_data_received_cb(), bt_socket_unset_connection_state_changed_cb()).
Related Features
This API is related with the following features:
It is recommended to design feature related codes in your application for reliability.
You can check if a device supports the related features for this API by using System Information,thereby controlling the procedure of your application.
To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.
More details on featuring your application can be found from Feature Element.
Asynchronous Operations
Callback(Event) Operations
Please refer Bluetooth Tutorial if you want to get more detailed usages and information of this api.
Typedef Documentation
Enumeration Type Documentation
Enumerations of Bluetooth socket connection state.
- Since :
- 2.3.1
- Enumerator:
BT_SOCKET_CONNECTED |
RFCOMM is connected
|
BT_SOCKET_DISCONNECTED |
RFCOMM is disconnected
|
Enumerations of connected Bluetooth device event role.
- Since :
- 2.3.1
- Enumerator:
BT_SOCKET_UNKNOWN |
Unknown role
|
BT_SOCKET_SERVER |
Server role
|
BT_SOCKET_CLIENT |
Client role
|
Function Documentation
Registers a rfcomm server socket with a specific UUID.
- Since :
- 2.3.1
- Privilege Level:
- public
- Privilege:
- http://tizen.org/privilege/bluetooth
- Parameters:
-
[in] | service_uuid | The UUID of service to provide |
[out] | socket_fd | The file descriptor of socket to listen |
- Returns:
- 0 on success, otherwise a negative error value.
- Return values:
-
- Precondition:
- The state of local Bluetooth must be BT_ADAPTER_ENABLED.
- See also:
- bt_socket_listen_and_accept_rfcomm()
-
bt_socket_destroy_rfcomm()
Register a callback function that will be invoked when a RFCOMM connection is requested.
- Since :
- 2.3.1
- Parameters:
-
[in] | callback | The callback function to register |
[in] | user_data | The user data to be passed to the callback function |
- Returns:
- 0 on success, otherwise a negative error value.
- Return values:
-
- Precondition:
- The Bluetooth service must be initialized with bt_initialize().
- Postcondition:
- If you listen and accept a socket by bt_socket_listen_and_accept_rfcomm(), bt_socket_connection_requested_cb() will be invoked.
- See also:
- bt_initialize()
-
bt_socket_unset_connection_requested_cb()