Click here to Skip to main content
15,881,803 members
Articles / Mobile Apps / Windows Mobile

Pocket PC 2003 File transfer - The OBEX way

Rate me:
Please Sign up or sign in to vote.
4.50/5 (14 votes)
1 Feb 2004CPOL4 min read 207.8K   1.1K   43   56
A sample application that pulls files from an OBEX server.

Introduction

OBEX is standard for infrared or Bluetooth communication, best suited for small devices, and it is supported on the PocketPC platforms. Why not use it for simple data synchronization tasks?

This sample application connects to the Obex-FTP service on a desktop (or server), retrieves the file list of a special folder in the servers Obex-FTP root, and then pulls the modified files to merge them with its own database.

In this way the server application can simply write new information into this dedicated folder, and the clients (our PocketPC app) can connect and synchronize from time to time. The server may be any device with a Obex-FTP server (a desktop with a bluetooth stick, another PocketPC, a Palm, or even a SmartPhone).

Background

An OBEX server publishes a list of "services" clients can connect to. The default and most basic of this services is the OBEX Inbox (or OBEX Object Push). This service, however, does normally not allow to pull (or GET) data other than some predefined default objects (like a vCard) from the server; and because of this it is not approriate for the purpose of this sample.

The OBEX FTP service however has all the functionally we need: get a list of files and folders, get, store, and delete files, and much more. All devices with an OBEX server that supports this services - whether they use infrared or Bluetooth communication - can act as a synchronization server for our client.

There are other OBEX services like IrMCSync or SYNCML or even custom OBEX extensions which could be used for synchronization (you can download the OBEX specification here) but none of them is as simple and versatile as the FTP approach.

Using the code

The class CObexFTP is a wrapper for the system supplied IObex object; use it detect appropriate devices in range and spawn instances of CObexFTPConnection which in turn encapsulates the IObexDevice interface and adds some useful methods for file transfer applications.

Typically you will derive your own class from CObexFTP and override the virtual function OnDeviceArrived to connect to this device and perform file transfer operations. Likewise you could override the functions OnDeviceRemoved and OnDeviceChanged, which will only be called if you have an active connection and will probably better be overridden in the corresponding CObexFTPConnection objects.

Once you have successfully initialized your instance (see CObexFTP::Initialize()) you can call the functions StartDeviceEnumeration() and StopDeviceEnumeration() to start/stop getting asynchrounous notifications through the above mentioned virtual functions.

Typically in your override of OnDeviceArrived you will create a CObexFTPConnection object (or a derived class) and call the Connect method. Since this methods keeps a pointer in a linked list you should not delete this object without calling Disconnect first!

The argument of OnDeviceArrived is a pointer to a standard IPropertyBag object; if you need more information about the device before accepting the connecting, the helper class CObexDeviceProperties may be of interest.

//
// Sample override of OnDevicedArrived
//
void CMyObex::OnDeviceArrived(IPropertyBag *Props)
{
  CObexDeviceProperties DevProps(Props);
  if (0==wcsicmp(DevProps.GetName(),L"ServerName"))
  {
    CMyObexConnection *pConn=new CMyObexConnection;
    if (pConn->Connect(this,Props))
    {
      // ... work with it
      pConn->Disconnect();
      delete pConn;
    }
  }
}

The sample application

The sample application uses WTL7.1 which has built-in CE-support (you can download it for free directly from Microsoft) because the OBEX classes use ATL anyway.

It simply connects to the first arriving FTP-server, changes to the folder "SampleFolder" and shows the name of all files that have changed since the last synchronization in a listbox.

If you want to play with it (e.g. with a desktop server running the WIDCOMM bluetooth stack), you have to create this folder in your servers FTP directory and put some files in it.

You will need embedded Visual C 4.2 and the PocketPC Platform SDK to compile the source; for the sample project file (PocketObex.vcp) you further need WTL7.1 installed and integrated into eVC.

A word of caution

I developed and tested this classes and the sample application on a T-Mobile MDA-II (which is also known as O2-XDA-II or similar). This seems to be the first device with a built-in Microsoft Bluetooth stack, most other vendors seem to use the WIDCOMM stack. I doubt that the Microsoft OBEX support properly integrates with the WIDCOMM stack, but I'd love to hear otherwise (:.

BTW: If you have a MDA-II (which is a great device!) and have wondered why there is no OBEX-FTP server on your device even after the latest firmware upgrade: There is no reason other than somebody (Microsoft?, HCT?, T-Mobile?,O2?) decided not to install it. If you simply compile the sample in the Microsoft WINCE-420 and put some registry values in, it works.

Open Issues

These classes currently do not care for authentication; if you have problems connecting to your server, make sure you switch off the "Secure connection" or similar for the FTP service on the server side.

If you would have to transfer larger amounts of data, some kind of progress indicator and a CANCEL button would be nice to have.

History

  • Jan 2004: First release.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Germany Germany
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionHow do i use the Demo Application? Pin
saravanababu6-Oct-09 22:58
saravanababu6-Oct-09 22:58 
GeneralNot able to find obex.h included in obexutil.h Pin
kashdk16-Dec-08 18:23
kashdk16-Dec-08 18:23 
Questionhow to trasfer image file (*jpg,*.bmp....)? Pin
Harish Sharma12-May-08 7:17
Harish Sharma12-May-08 7:17 
QuestionBluetooth Communication Pin
kathalora7-Nov-07 15:22
kathalora7-Nov-07 15:22 
QuestionHelp: It Cannot find any server on device Pin
binguo2-Aug-07 0:59
binguo2-Aug-07 0:59 
GeneralUsing Broadcom GetFile :confused: Pin
samyharris15-Jun-07 8:58
samyharris15-Jun-07 8:58 
GeneralError message :( Pin
Dali Hammadi19-Mar-07 5:39
Dali Hammadi19-Mar-07 5:39 
GeneralRe: Error message :( Pin
MBuehrer19-Mar-07 5:45
MBuehrer19-Mar-07 5:45 
GeneralRe: Error message :( Pin
Dali Hammadi21-Mar-07 6:36
Dali Hammadi21-Mar-07 6:36 
GeneralSmartphone , Discovery Prolem Pin
Member 37832911-Feb-07 20:01
Member 37832911-Feb-07 20:01 
GeneralInfo in PropertyBag Pin
tm0594610-Jan-07 22:20
tm0594610-Jan-07 22:20 
QuestionCan I use this source code for smartphone (with changes) Pin
sfj39-Dec-06 11:08
sfj39-Dec-06 11:08 
GeneralSmartphone Comaptibility Pin
babiqescobar28-Oct-06 6:40
babiqescobar28-Oct-06 6:40 
QuestionTransfer contact from PDA? Pin
viettho4-Aug-06 5:57
viettho4-Aug-06 5:57 
GeneralSame thing for XP Pin
kazak_dev2-Apr-06 23:04
kazak_dev2-Apr-06 23:04 
QuestionHow to use PutFile? Pin
Goutam Das8-Mar-06 18:56
Goutam Das8-Mar-06 18:56 
Generalobex object push. Pin
gdx990321-Dec-05 10:54
gdx990321-Dec-05 10:54 
GeneralCan't find atlresce.h? everybody help me ! thanks Pin
falasnow31-Jul-05 15:33
falasnow31-Jul-05 15:33 
GeneralRe: Can't find atlresce.h? everybody help me ! thanks Pin
MBuehrer31-Jul-05 19:56
MBuehrer31-Jul-05 19:56 
Questionwhat about Windows XP? Pin
matro21-Jul-05 13:35
matro21-Jul-05 13:35 
GeneralThanks + Large File Issue Pin
jfdragon23-Jun-05 11:02
jfdragon23-Jun-05 11:02 
GeneralRe: Thanks + Large File Issue Pin
MBuehrer24-Jun-05 3:34
MBuehrer24-Jun-05 3:34 
GeneralRe: Thanks + Large File Issue Pin
parama_chakra4-Dec-05 17:33
parama_chakra4-Dec-05 17:33 
Hi JustinWF
I am using iPAQ 5500. When I run the app it comes up with "Searching for Server"
If I terminate the app and use the bluetooth manager to connect to "File Transfer" I can see the designated folder on the PC.
Both my dongle and iPAQ 5500 use Widcomm stack.
Regards
joe


If winter comes is spring far behind? - (PBShelley -Ode to the West Wind)
GeneralCan't find ObexStrings.h Pin
BakaOnigiri11-May-05 3:22
BakaOnigiri11-May-05 3:22 
GeneralRe: Can't find ObexStrings.h Pin
MBuehrer16-May-05 4:58
MBuehrer16-May-05 4:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.