Introduction
This application contains a number of web pages to display on an iPhone as well as Java programs to run on a laptop so that the user on the IPhone can control aspects of a machine with her IPhone. Example that one could make with these concepts are iTunes controllers, presentation controllers, remote controllers, and the list goes on.
Overview
A typical application control flow is the following:
- A server (Java program) is started on a laptop.
- An IPhone requests a page from http://jeffpalm.com/iwebapp and the user enters the local IP address of the machine running the server program.
- Requests go from the web page on the IPhone to the local machine, and the server program handles these requests. The server program, then, responds, and some action is taken both on the local machine and the web page being displayed in the laptop.
By doing this, we can have control of local resources on a laptop by an IPhone and have the display coming from a remote machine.
Conventions
In all this package contains the following types of files:
- Java files to be run on a laptop.
- PHP files to display web pages.
- Javascript files to run on an IPhone and display as well as communicate with a local computer.
- CSS files to control the display of web pages.
A single page (or application) usually contains only one of each of the above files. Normally an application will have a name, let's say Name, with a counterpart lower case name. For a running example, let's assume our application is called Remote, so that the corresponding lower case name is remote. For this application we would have the following files.
- A Java file which handles requests coming from a phone called Remote.java.
- A PHP file the displays the interface called remote.php.
- A Javascript file to handle the communication to the local machine as well as display functionality called remote.js.
- A CSS file for application-specific display information called remote.css.
To run this program, we would create a target in the Makefile called remote, so that to run it we would type
make remote
Files
Some notable files are the following
- Java files
- Handler.java defines the interface Handler. Such instances should respond to a certain command and extend AbstractHandler to implement the method String handle(Map<String,String>) to respond to these commands. For example, we could define an instance to simply print out a message when a message Hello is sent to the local machine:
class HelloHandler extends AbstractHandler {
public void handle(java.util.Map<String,String> args) {
System.out.println("hello");
return OK;
}
}Note that AbstractHandler uses reflection to respond to the Hello command, and OK is a predefined constant.
- LocalServer.java contains the class LocalServer and all servers should extend this class. Functionality is added by implementing Handler[] getHandlers() to return the Handlers to which this server responds.
Details
Add your content here. Format your content with:
- Text in bold or italic
- Headings, paragraphs, and lists
- Automatic links to other wiki pages