Java Reference
In-Depth Information
web server. (Or, of course, I could use SimpleProxyServer to set up a proxy Þnger
server for my host on the host that runs the web server.)
If your system doesn't run the Þnger server itself, trying out this applet may be a
little tricky. What you can do is find some host out on the Net that does provide
the Þnger service. (I've used rtfm.mit.edu , for example.) Then use SimpleProxy-
Server to run a local proxy for that finger server and run the applet locally on
your machine. You have to modify the applet slightly to make it connect to the
desired proxy port, instead of the reserved Þnger port, 79, however.
Example 5•7: Who.java
package com.davidflanagan.examples.net;
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
/**
* This applet connects to the "finger" server on the host
* it was served from to determine who is currently logged on.
* Because it is an untrusted applet, it can only connect to the host
* from which it came. Since web servers do not usually run finger
* servers themselves, this applet will often be used in conjunction
* with a proxy server, to serve it from some other host that does run
* a finger server.
**/
public class Who extends Applet implements ActionListener, Runnable {
Button who; // The button in the applet
/**
* The init method just creates a button to display in the applet.
* When the user clicks the button, we'll check who is logged on.
**/
public void init() {
who = new Button("Who?");
who.setFont(new Font("SansSerif", Font.PLAIN, 14));
who.addActionListener(this);
this.add(who);
}
/**
* When the button is clicked, start a thread that will connect to
* the finger server and display who is logged on
**/
public void actionPerformed(ActionEvent e) { new Thread(this).start(); }
/**
* This is the method that does the networking and displays the results.
* It is implemented as the body of a separate thread because it might
* take some time to complete, and applet methods need to return promptly.
**/
public void run() {
// Disable the button so we don't get multiple queries at once...
who.setEnabled(false);
// Create a window to display the output in
Frame f = new Frame("Who's Logged On: Connecting...");
Search WWH ::




Custom Search