Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

How to send descriptor over Bluetooth

From Wiki
Jump to: navigation, search
Article Metadata
Code ExampleArticle
Created: mahbub_s60 (23 Jul 2008)
Last edited: hamishwillee (25 Jul 2012)



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:

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;
iListeningSocket.Accept(iAcceptedSocket, iStatus);

and in RunL()

        case EConnected:            
// 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.

void CMessageServer::RequestData()
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.

        case EBTPointToPointSendMessage:
iClient->SendMessageL(_L8("Hello Client"));
else if(iServer->IsConnected())
iServer->SendMessageL(_L8("Hello Server"));

SendMessageL() of server side is like this.

void CMessageServer::SendMessageL(const TDesC8& aData)	
// cancel any read requests on socket
if(EDisconnected != iState)
// send message
iAcceptedSocket.Write(aData, iStatus);

When the data has been sent, we get our RunL() called with current state ESending. So we can go again to receive mode.

    switch (iState)
case ESending:

Example Applications

The application is tested with E65 & N95 8GB, can be found here: File:BtChatown

This page was last modified on 25 July 2012, at 23:04.
45 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.


Thank you!

We appreciate your feedback.