Trail: Deployment
Lesson: Applets
Section: Practical Considerations When Writing Applets
Subsection: Working with a Server-Side Application
A Simple Network Client Applet
A Simple Network Client Applet
This section talks about the client to be an applet. Here's the applet source code. The client has been written not only to communicate with the host the applet came from, but also to have a graphical UI, and to have a loop so that it can get as many quotes as you like. You can run the applet by including it in a page with the following HTML code:
<APPLET CODE=QuoteClientApplet.class WIDTH=500 HEIGHT=100>
</APPLET>

Here's a link to a page that contains the above HTML code. By saving this page to a file on your local HTTP server, you can use it to communicate with the server-side application that will be running on the HTTP server. You must also save the compiled form of the applet to the same directory.

Before the applet can get quotes, you need to run the server on the host that the applet came from. You then need to note the number of the port that the server is listening on. After you enter this port number into the applet, it will hook up with the server and you'll be able to get one-line quotations. Below are detailed instructions, followed by pictures of the server and the applet in action.

  1. Compile QuoteServer.java and QuoteServerThread.java. Here's a text file ( one-liners.txt) that should be in the same directory as the resulting class files.
  2. On the computer that serves the applet class file (through HTTP), invoke the interpreter on the QuoteServer class. For example, if you view the applet's page with the URL http://mymachine/quoteApplet.html, then you need to run the server on the host named mymachine.
  3. Record the port number that the quote server displays.
  4. Enter this number into the applet's text field.
  5. Press the Send button to request a quote from the server. You should see a quote appear in the text area.
Here's a picture of the applet in action:

QuoteServer sample output

QuoteServer sample output

Previous page: Working with a Server-Side Application
Next page: Using a Server to Work Around Security Restrictions