Click here to Skip to main content
Click here to Skip to main content

Pocket PC 2003 File transfer - The OBEX way

, 1 Feb 2004 CPOL
Rate this:
Please Sign up or sign in to vote.
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)

Share

About the Author

MBuehrer
Web Developer
Germany Germany
No Biography provided

Comments and Discussions

 
QuestionHow do i use the Demo Application? Pinmembersaravanababu6-Oct-09 23:58 
GeneralNot able to find obex.h included in obexutil.h Pinmemberkashdk16-Dec-08 19:23 
Questionhow to trasfer image file (*jpg,*.bmp....)? PinmemberHarish Sharma12-May-08 8:17 
QuestionBluetooth Communication Pinmemberkathalora7-Nov-07 16:22 
QuestionHelp: It Cannot find any server on device Pinmemberbinguo2-Aug-07 1:59 
GeneralUsing Broadcom GetFile :confused: Pinmembersamyharris15-Jun-07 9:58 
GeneralError message :( PinmemberDali Hammadi19-Mar-07 6:39 
GeneralRe: Error message :( PinmemberMBuehrer19-Mar-07 6:45 
GeneralRe: Error message :( PinmemberDali Hammadi21-Mar-07 7:36 
GeneralSmartphone , Discovery Prolem PinmemberMember #37832911-Feb-07 21:01 
GeneralInfo in PropertyBag Pinmembertm0594610-Jan-07 23:20 
QuestionCan I use this source code for smartphone (with changes) Pinmembersfj39-Dec-06 12:08 
GeneralSmartphone Comaptibility Pinmemberbabiqescobar28-Oct-06 7:40 
QuestionTransfer contact from PDA? Pinmemberviettho4-Aug-06 6:57 
GeneralSame thing for XP Pinmemberkazak_dev3-Apr-06 0:04 
QuestionHow to use PutFile? PinmemberGoutam Das8-Mar-06 19:56 
Generalobex object push. Pinmembergdx990321-Dec-05 11:54 
GeneralCan't find atlresce.h? everybody help me ! thanks Pinmemberfalasnow31-Jul-05 16:33 
GeneralRe: Can't find atlresce.h? everybody help me ! thanks PinmemberMBuehrer31-Jul-05 20:56 
Questionwhat about Windows XP? Pinmembermatro21-Jul-05 14:35 
GeneralThanks + Large File Issue PinmemberJustinWF23-Jun-05 12:02 
GeneralRe: Thanks + Large File Issue PinmemberMBuehrer24-Jun-05 4:34 
GeneralRe: Thanks + Large File Issue Pinmemberparama_chakra4-Dec-05 18:33 
GeneralCan't find ObexStrings.h PinmemberBakaOnigiri11-May-05 4:22 
GeneralRe: Can't find ObexStrings.h PinmemberMBuehrer16-May-05 5:58 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.1411019.1 | Last Updated 2 Feb 2004
Article Copyright 2004 by MBuehrer
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid