This page was last modified 09:05, 2 May 2008.
CS000936 - Discovering Bluetooth devices
From Forum Nokia Wiki
| ID | CS000936 | Creation date | May 2, 2008 |
| Platform | S60 3rd Edition, MR | Tested on devices | Nokia N95 |
| Category | Symbian C++ | Subcategory | Bluetooth |
| Keywords (APIs, classes, methods, functions): RHostResolver, RSocketServ, TInquirySockAddr, RHostResolver::GetByAddress(), RSocketServ::FindProtocol() |
Overview
RHostResolver provides an interface to host name resolution services, such as DNS, that may be provided by certain protocol modules.
The interface provides functions to access the following facilities:
- Obtaining names from addresses
- Obtaining addresses from names
- Getting and setting local host name
Before using any service, a connection to a socket server session must be established.
Each function is available in both synchronous and asynchronous versions.
The following codes show how to search Bluetooth devices with RHostResolver.
MMP file
The following capabilities and libraries are required:
CAPABILITY LocalServices LIBRARY esock.lib LIBRARY bluetooth.lib
Header file
#include <es_sock.h> #include <bt_sock.h> RSocketServ iSocketServ; RHostResolver iResolver; TInquirySockAddr iAddr;
Source file
CMyDeviceDiscoverer must be an active object (derived from CActive).
_LIT(KBTLinkManagerTxt,"BTLinkManager"); void CMyDeviceDiscoverer::ConstructL() { ... // Get socket server session User::LeaveIfError(iSocketServ.Connect()); ... } void CMyDeviceDiscoverer::DiscoverDevicesL() { if (!IsActive()) { // Load protocol for discovery TProtocolDesc pdesc; User::LeaveIfError( iSocketServ.FindProtocol(KBTLinkManagerTxt(), pdesc)); // Initialize host resolver iResolver.Close(); User::LeaveIfError( iResolver.Open(iSocketServ, pdesc.iAddrFamily, pdesc.iProtocol)); // Start device discovery by invoking remote address lookup iAddr.SetIAC( KGIAC ); iAddr.SetAction(KHostResInquiry|KHostResName|KHostResIgnoreCache); iResolver.GetByAddress(iAddr, iEntry, iStatus); SetActive(); } else { User::Leave(KErrNotReady); } } void CMyDeviceDiscoverer::RunL() { // RHostResolver.GetByAddress() has completed, process results if ( iStatus!=KErrNone ) { // All devices find } else { // New device data entry // Device name iEntry().iName; // Device address static_cast<TBTSockAddr>(iEntry().iAddr).BTAddr(); // Get next discovered device iResolver.Next(iEntry, iStatus); SetActive(); } } void CMyDeviceDiscoverer::DoCancel() { iResolver.Cancel(); } CMyDeviceDiscoverer::~CMyDeviceDiscoverer() { Cancel(); iResolver.Close(); }
Postconditions
CMyDeviceDiscoverer finds existing Bluetooth devices.
See also
CS000937 - Discovering Bluetooth services
CS000938 - Advertising Bluetooth services
CS000939 - Establishing a Bluetooth connection
KIS000330 - RHostResolver and redundant display of access point selection dialog
Example application
This code snippet has been used in the S60 Platform: Bluetooth Point-to-multipoint Example application.
| Related Discussions | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Closing a bluetooth connection | Alfury | Mobile Java Networking & Messaging & Security | 4 | 2008-04-01 16:18 |
| Bluetooth Question | mammoned | Bluetooth Technology | 0 | 2004-12-02 16:27 |
| Using Java | ntsing | Mobile Java General | 1 | 2002-10-09 07:12 |
| RSendAsMessage - передача файлов по Bluetooth | Den123 | Russian Developer Forum - Форум Российских разработчиков | 2 | 2008-03-06 17:28 |
| Set automatically pin code for an incoming connection in Bluetooth. | ajsanchez | Symbian Networking & Messaging | 14 | 2004-10-27 15:09 |

