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);
}