Share via


Connecting to an OBEX Server (Windows Embedded CE 6.0)

1/6/2010

Connect requests are optional. If a Connect request is not issued before a IObexDevice::Get or IObexDevice::Put command, a default packet size of 255 bytes is assumed.

To send a Connect request to the server, pass the headers in the IObexDevice::Connect method. Response, sent by the server, includes headers in the property bag that is returned from IObexDevice::Connect.

The following code example is an excerpt from the sample function, Connect, that is defined in filebrowser.h.

For Windows Embedded CE, the filebroswer.h file is at %_WINCEROOT%\Public\Servers\SDK\Samples\OBEX\OBEXTOOL.

**.

This example shows how to add a target header and then connect to an OBEX Server

Note   To make the following code example easier to read, error checking is not included. This code example should not be used in a release configuration unless it has been modified to include secure error handling.

//Declare interface pointers.
IObexDevice *pObexDevice;
IObex *pObex;
IHeaderCollection *pHeaderCollection = 0;
//Get a Header Collection.
HRESULT hr = CoCreateInstance(CLSID_Obex, 
                NULL, 
                CLSCTX_INPROC_SERVER, 
                IID_Obex, 
                (void**)&pObex);
...//A call to notify returns the property bag in the pUnk1 parameter
...//Discover Obex devices
);
HRESULT hr = CoCreateInstance(CLSID_HeaderCollection, 
                NULL, 
                CLSCTX_INPROC_SERVER, 
                IID_HeaderCollection, 
                (void**)&pHeaderCollection);
pHeaderCollection->AddTarget(sizeof(CLSID_FileExchange_NetOrder),
                      (UCHAR *)&CLSID_FileExchange_NetOrder;
//Connect to the OBEX server.
hr = BindToDevice(pBag, pObexDevice);
hr = pObexDevice->Connect(NULL, 0, pHeaderCollection);

The packet length varies depending on included headers.

For more information, see the OBEX specification at this Official IrDA Web site.

The following optional headers can be used in a Connect request:

  • Target is used to specify a service. If a target is not specified, the default inbox service is assumed.
  • Authenticate Challenge is used by theclient when authenticating with a server.
  • Authenticate Response is sent by the client when responding to a server challenge.

The OBEX version is 1.2 and the flags are always set to 0.

The maximum packet length varies depending upon the packet's configuration.

The following optional headers can be used in a Connect response:

  • Who contains the same information specified in the request target header.
  • Authenticate Challenge is sent by the server when a client is authenticating.
  • Authenticate Response is sent by the server to indicate a successful challenge/response.

See Also

Concepts

Client Support
Discovering OBEX Devices