Read the whole "Device Programming with MIDP" series:
Networked devices can use numerous protocols to communicate with each other. In this article, I'll focus on the HttpConnection interface that you can use to access information stored on a Web server. Preceding the article's example, I will discuss
the interactions of the javax.microedition.io interfaces and classes. The example will concentrate on the interaction between a MIDP device and a JSP-based system.
All interfaces in the javax.microedition.io package are based on the Connection interface. Other connection interfaces inherit the method contained in Connection and define methods used for accessing relevant variables and actions of that Connection type. I will discuss the more common interfaces in this article; the other interfaces are left to the reader for investigation.
The HttpConnection interface provides other methods on top of the Connection interface to enable HTTP interaction. Here is a list of some of those useful methods:
String getHeaderField(int index)String getHeaderField(String name)long getHeaderFieldDate(String name, long def)int getHeaderFieldInt(String name, int def)String getHeaderFieldKey(int n)String getHost()long getLastModified()int getPort()String getProtocol()String getQuery()String getRef()String getRequestMethod()String getRequestProperty(String key)int getResponseCode()String getResponseMessage()String getURL()void setRequestMethod(String method)void setRequestProperty(String key, String value)These methods let you access the HTTP fields just as you would in a servlet-based system.
The other interfaces are well documented in the API specification. Those interfaces will contain methods for sending datagram packets and streaming data to and from the device using a variety of protocols. I will not examine those in detail because while they differ in exact method signature, they are obtained in an identical fashion.
How does the MIDP API figure out which interface to create and return to the calling class? The answer is that the proper
Connector is returned based upon the value passed in the connection string.
The following connection string alerts the Connector object that the system is looking for an HttpConnection:
HttpConnection httpConn = Connector.open("http://www.itpath.com");
The MIDP Connector object parses through the connection string and determines that it is a URL for accessing a Webpage. An implementation of
the HttpConnection interface is returned to the calling class.
Nice ArticleBy Anonymous on December 5, 2008, 8:50 amHi Michael Cymerman its very nice and fantastic article and very easy understandable for freshers thanks i got the relavant approach for my search thank you a lot
Reply | Read entire comment
View all comments