OBEX Samples (Compact 2013)

3/26/2014

The samples provide a base for implementing the Object Exchange (OBEX) Protocol technology. These samples have not been tested and are not intended for production use.

Samples are located in %_WINCEROOT%\Public\Servers\SDK\Samples\OBEX.

OBEXFTP

This sample application illustrates how to establish FTP services using the Windows Embedded Compact-based Bluetooth stack over OBEX.

Usage

obexftp

Remarks

When the application starts, you can use the command connect to connect to a Bluetooth device in the vicinity. The application will display a list of Bluetooth devices during the connection process. Choose the one that you want to perform FTP operations on. After the connection is established, you can perform typical FTP operations such as put, get, cd, and dir. Terminate the session using the disconnect command.

Sample code for ObexFTP is provided in %_WINCEROOT%\Public\Servers\SDK\Samples\OBEX\ObexFTP.

OBEXTool

This sample application provides a user interface (UI) to manage or establish FTP services using the Windows Embedded Compact-based Bluetooth stack over OBEX.

Usage

obextool

Remarks

When the application starts, you can use the connect menu option to connect to a Bluetooth device in the vicinity. The application will display a list of Bluetooth devices in a dialog box during the connection process and you can choose the one that you want to perform FTP operations on. After the connection is established, you can use the send file option to send a file to the connected Bluetooth device. Terminate the session using the disconnect menu option.

Sample code for ObexTool is provided in %_WINCEROOT%\Public\Servers\SDK\Samples\OBEX\FileBrowser. To view the OBEX sample, install Platform Builder and then build a sample OS design that includes OBEX. You can then find the OBEX sample in %_WINCEROOT%\Public\<your OS design name>\SDK\Samples\OBEX\FileBrowser.

The two most common tasks in OBEX are to Get and Put a data object. The client is the initiator of these commands and the server, upon receiving these commands, carries out the service requested.

Implementing the Get Operation

Getting a default vCard involves pulling a file from the server. A vCard contains contact information that can be shared between devices. If a server contains an updated version of a global contact list, a vCard can be used to update clients with the latest contact information.

To implement this functionality, the following steps are required:

  1. Create an instance of the following interfaces:

  2. Initialize the IObex interface by calling the IObex::Initialize method.

  3. To obtain a list of available devices, call the IObex::EnumDevices method. Alternatively, call the IObexSink::Notify method to obtain a list of available Bluetooth devices.

  4. Using the IHeaderCollection interface, build the collection of headers that you would like to pass into the IObexDevice::Connect method.

  5. Using the information from IObex::EnumDevices, connect to the desired device with the IOBexDevice::Connect method.

  6. Using the IHeaderCollection interface, build the collection of headers that you would like to pass into the IObexDevice::Get method. This collection is used to describe the object you are pulling. Set the Type header to text/x-vCard.

  7. Call the IObexDevice::Get method. Include the collection of headers that describe the object.

  8. The IObexDevice::Get method returns a stream. Use the IStream interface to read the stream.

  9. When finished, release the stream.

  10. To release the connection, call the IObexDevice::Disconnect method.

  11. To release the IObex interface and allocated resources, call the IObex::Shutdown method.

  12. Release all other interfaces.

Implementing the Put Operation

A client-side push is the most common application of OBEX. It enables clients to transfer files to a server. A common scenario for this functionality would be a user transferring a calendar schedule to a PDA.

To implement this functionality, the following steps are required:

  1. Create an instance of the following interfaces:

  2. Initialize the IObex interface by calling the IObex::Initialize method.

  3. To obtain a list of available devices, call the IObex::EnumDevices method. Alternatively, call the IObexSink::Notify method to obtain a list of available Bluetooth devices.

  4. Using the IHeaderCollection interface, build the collection of headers that you would like to pass into the IObexDevice::Connect method.

  5. Using the information from IObex::EnumDevices, connect to the desired device with the IOBexDevice::Connect method.

  6. Using the IHeaderCollection interface, build the collection of headers that you would like to pass into the IObexDevice::Put method. This collection is used to describe the object you are pushing.

  7. Call the IObexDevice::Put method. Include the collection of headers that describe the object.

  8. The IObexDevice::Put method returns a stream. Use the IStream interface to write the stream to the server.

  9. When finished, release the stream.

  10. To release the connection, call the IObexDevice::Disconnect method.

  11. To release the IObex interface and allocated resources, call the IObex::Shutdown method.

  12. Release all other interfaces.

See Also

Reference

OBEX Registry Settings

Other Resources

Object Exchange Protocol Reference