![Symbian Developer Library](../../../../../../../../a_stock/images/mainheading.gif)
![]() |
![]() |
|
Once the device and service have been established, you can connect to the remote service and start using it.
Connect to the device through the Connect()
function of
the generic Symbian OS socket interface RSocket
. Bluetooth
sockets can be opened using the L2CAP and RFCOMM protocols. For an L2CAP
Bluetooth socket, the "port" is the Protocol/Service Multiplexer (PSM) to which
to connect; for an RFCOMM the port is the server channel. Where these values
are not known, they can be read from the service attribute
ProtocolDescriptorList
. See
Using Bluetooth Service Discovery Agent for details.
You can read and write data using the socket in whatever format the target service expects (AT commands, text, HTTP, PPP etc).
// Assume have a TInquirySockAddr object, addr, with relevant device info
// Connect an L2CAP socket
RSocket socket;
// although CBluetoothSocket may be a better option.
RSocketServ socketServ;
TRequestStatus status;
User::LeaveIfError(socket.Open(socketServ,KBTAddrFamily,KSockSeqPacket,KL2CAP));
User::LeaveIfError(socket.Connect(addr,status));
User::WaitForRequest(status);
if (status == KErrNone)
{
// Write some simple data
_LIT8(KDataToWrite,"01234");
socket.Write(KDataToWrite,status);
User::WaitForRequest(status);
}
// Close socket
socket.Close();
For both the RFCOMM and L2CAP protocols, no data can be sent or
received in the Connect()
and
Shutdown()
calls. The versions of these calls that take
extra data panic.
RFCOMM uses sockets of the stream socket
(KSockStream
) type.
L2CAP uses sockets of the sequenced packet
(KSockSeqPacket
) type.
This tutorial set takes you through all the steps involved in setting up and communicating over a Bluetooth connection.
Connecting and Transferring Data to a Remote Device - This document