How to send descriptor over Bluetooth
This tutorial introduces how to send a descriptor over Bluetooth link and this will also show how a server socket will work as receiver and sender of descriptor message. The example is modified based on Bluetooth chat example found in SDK. Here we just show how to send descriptor or binary data, for file sending you could see obex example: S60_Platform_Bluetooth_OBEX_Example_v1_0_en.zip.html
Two socket for server side and one socket for client side
A BT device can work as client or server at the same time. If it want to work as server (waiting for some other BT device to be connected to it) it should have a listening socket and an accepting socket. When a connection request is occurred then accepting socket is given the handle, it is then used to transfer data. After this listening socket may be used to monitor further connections.
iAcceptedSocket.Close(); // close old connection - if any
User::LeaveIfError(iAcceptedSocket.Open(iSocketServer)); // Open abstract socket
iState = EConnected;
and in RunL()
// do not accept any more connections
After establishing the connection, accepted socket goes to receive mode, so it will receive data. RequestData() method is like this.
iState = EWaitingForMessage;
iAcceptedSocket.RecvOneOrMore(iBuffer, 0, iStatus, iLen);
Sending data over BT by client or server
We can send data either by client side or by server side. If client is connected we use client side if not then we use server side.
SendMessageL() of server side is like this.
void CMessageServer::SendMessageL(const TDesC8& aData)
// cancel any read requests on socket
if(EDisconnected != iState)
// send message
When the data has been sent, we get our RunL() called with current state ESending. So we can go again to receive mode.
The application is tested with E65 & N95 8GB, can be found here: File:BtChatown S60.zip