Header Sep

Java Tips, Tricks & Code

My Rating Score
Login to rate page

September 2003

J2ME Networking with the MicroGraph Application

 

MicroGraph is a client-server J2ME code sample that draws the result of a mathematical equation to the display of the phone. The results is calculated by passing the equation on to an HTTP server which replies with a set of coordinates that are drawn to the display of the mobile device.

If the latency of the wireless network is reasonably small, the user of the MIDP client would get the impression that his/her mobile device is able to draw complex graphs using constants like pi and e, trigonometric functions, logarithms, and even decimal numbers (floats).

As you probably know, neither floating points nor these mathematical functions are supported in the CLDC 1.0 configuration. For this reason, MicroGraph not only shows a simple technique to perform client-server networking over HTTP, but it also demonstrates how you can easily extend the limits of the CLDC/MIDP platform by moving some procedures to the server side.

Note: To run the sample code you need to have an HTTP server.

There are many ways to set up an HTTP server and in the sample we present only one of them. The server side of MicroGraph is a java servlet (named MicroGraphServlet) running on top of a Tomcat servlet engine (http://jakarta.apache.org/tomcat/). An ordinary Apache HTTP server with a servlet engine would also do the work. The MicroGraphServlet uses the JEP library from Singular Systems (http://www.singularsys.com/jep/) to create instances of MicroGraph's EquationParser class that can parse given equation strings and convert the calculated values to screen coordinates adapted to the client device. If one or more of the equations is illogical then a response message will be set up triggering an alert on the client side informing of the invalid equation.

Download Sample Code
micrograph_1_0.zip

My Rating Score
Login to rate page