Transferring data over a Bluetooth connection

The S60 platform allows you to send to or receive data from other devices over a Bluetooth connection, once your application has discovered a suitable device within the range of the Bluetooth technology.

Typical use cases include:

Important implementation considerations include:

  • OBEX is usually considered a session-based connection, while L2CAP ad RFCOMM are used for continuous connections. OBEX does not require the maintenance of a continuous connection but it can add overhead that results in a poor throughput. L2CAP and RFCOMM can be more efficient in sending data.

  • There are limitations in implementing audio related Bluetooth connections from your application. You can send audio files over a Bluetooth connection, but you cannot stream audio over a Bluetooth SCO link.

  • Use of some Bluetooth configurations may require additional capabilities for your application. Note that most Bluetooth use cases can be used with the most basic signing method.

  • Mobility may cause breaks in Bluetooth connections if any of the connected devices moves out of the range during the connection. Your application must be prepared for unexpected connection breaks and always keep responsive to user actions.

Sending/receiving data over a Bluetooth connection

Prerequisites:

  • A connection has been initialized with another Bluetooth device or devices.

To transfer data over a Bluetooth connection:

  1. Use one of the following methods to send information to or receive information from the selected device(s):

    • To use a Bluetooth connection interactively, use the methods of the CBluetoothSocket class of the Bluetooth Sockets API.

      Note that you need to specify the underlying Bluetooth protocol to be used for the transfer.

    • To send or receive a file in a single-shot operation (OBEX), use the methods of the OBEX API.

      Note that you need to specify the underlying Bluetooth protocol to be used for the transfer.

      The following classes are particularly relevant:

    • To send a file wrapped up in a message over a Bluetooth connection, use the methods of the Send UI API through the CSendUI class.

      This connection is OBEX-based, as it uses the standard Bluetooth Object Push Profile (OPP).

  2. If you are using the Bluetooth connection interactively and you wish to include user authentication or data encryption for the data transfer, use the Bluetooth Security Manager API to set the security requirements for the outgoing socket. Typically the device that accepts the connection request sets these requirements.

  3. Unless you are sending a file wrapped up in a message (using the Send UI API), you need to close the connection when you have finished transferring data. The connection can also be closed by the remote application that has accepted the Bluetooth connection request.

  4. Make sure you have the correct capabilities information set for your application.

  5. Make sure the following libraries are accessible to your linker when compiling your application by including them in your mmp file or by editing the project properties in your IDE, depending on your build environment:

    • sendui.lib (to send a message over a Bluetooth connection)

    • obex.lib (to send or receive data in a single-shot operation)

    • bluetooth.lib and esock.lib (to use the Bluetooth connection interactively)

Additional information on transferring data over Bluetooth

For more information, see:

Related S60 platform services

The S60 platform also provides the following services:

  • Messaging for sending a file wrapped up in a message over a Bluetooth OBEX connection