Symbian Developer Library

SYMBIAN OS V6.1 EDITION FOR C++

[Index] [Glossary] [Previous] [Next]



How to connect and transfer data to a remote device

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 EPOC 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).

Example

// Assume have a TInquirySockAddr object, addr, with relevant device info

// Connect an L2CAP socket
RSocket socket;
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();

Notes