
|
June 2005 |
|
|
Until recently, J2ME developers for Sony Ericsson mobile phones have been unable to use Infrared connectivity for their apps. However, the Java Platform 5 (JP-5) changes that by including JSR-82 as one of the supported features. The Sony Ericsson mobile phones included in JP-5 are the K750, W800 and the K600 series. We will discuss the OBEX protocol in two separate articles. Here in the first article, we present a brief introduction, outline how to create a client application and provide a code sample to download. The second article, available later this summer, we will discuss the server side of the protocol. Introduction to the OBEX protocol The OBEX protocol has a defined set of operations that are used for handling and sending data. It uses a client/server request-response model. An OBEX Client is the entity that initiates the connection to an OBEX server and starts OBEX operations. There are eight operations that are defined in the OBEX protocol:
An OBEX session is started with the CONNECT operation and ended with the DISCONNECT operation. In between, the client can invoke any number of SETPATH, GET, PUT, CREATE-EMPTY or DELETE operations. Information about the object can be sent with headers. There are a number of defined headers for this purpose, a couple of them are:
Creating a client application As the OBEX API is based on the Generic Connection Framework (GCF) it is easy to create a normal HTTP connection.To create a client connection, you simply use the Connector.open(String url) method. The URL for OBEX should be formatted according to GCF framework: {protocol}:[{target}][{params}] where the protocol is set to "irdaobex". The target can be "discover", "addr", "conn", or "name". The "discover" target is used for searching for Infrared devices nearby and we will use this as we want to connect to any Sony Ericsson mobile phone in our immediate surroundings. The Connector factory returns a ClientSession object which is the client-side connection object for OBEX. It extends the Connection interface and adds methods for OBEX requests and defines headers for the OBEX operations. Use the ClientSession object to start a CONNECT operation. The returned Headerset object is used to add headers for this session. First, tell the OBEX server the length of the message. Then instruct the server that your message should be saved as JUMAR.TXT. We are now ready to initiate the PUT request with the defined header. The returned Operation object extends the ContentConnection interface and adds functionality for header manipulation. Use it to open an OutputStream to the server. Now you can send your message as a byte array to the server. Don't forget to end the session with the DISCONNECT operation and close the ClientSession, as well as the Operation and the OutputStream. You can easily send your message as a calendar note or a contact by formatting the message and specifying the correct file type with the NAME header. For example if you want to send a calendar note containing the message "Hello there" you first have to set the name header to the calendar notes file type ".vnt": head.setHeader(HeaderSet.NAME, "VNote.vnt"); This will make the receiving Sony Ericsson phone aware that there is a calendar note coming. Now format the message according to VNote format: BEGIN:VNOTE More information: | |
Copyright © 2001 - 2009 Sony Ericsson Mobile Communications AB. All Rights Reserved.