FileDocCategorySizeDatePackage
ProxyServer.javaAPI DocExample5777Mon Sep 22 13:30:32 BST 1997None

ProxyServer

public class ProxyServer extends Object
This class uses the Server class to provide a multi-threaded server framework for a relatively simple proxy service. The main() method starts up the server. The nested Proxy class implements the Server.Service interface and provides the proxy service.

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)
Create a Server object, and add Proxy service objects to it to provide proxy service as specified by the command-line arguments.

    try {
      // Check number of args.  Must be a multiple of 3 and > 0.
      if ((args.length == 0) || (args.length % 3 != 0))
        throw new IllegalArgumentException("Wrong number of arguments");

      // Create the Server object
      Server s = new Server(null, 12); // log stream, max connections

      // Loop through the arguments parsing (host, remoteport, localport)
      // tuples.  Create an appropriate Proxy object, and add it to the server
      int i = 0;
      while(i < args.length) {
        String host = args[i++];
        int remoteport = Integer.parseInt(args[i++]);
        int localport = Integer.parseInt(args[i++]);
        s.addService(new Proxy(host, remoteport), localport);
      }
    }
    catch (Exception e) {  // Print an error message if anything goes wrong.
      System.err.println(e);
      System.err.println("Usage: java ProxyServer " +
                         "<host> <remoteport> <localport> ...");
      System.exit(1);
    }