int port;
Class connectClass;
ClientConnection clientType;
ClassLoader loader = System.getClassLoader();
// Get the requested port number off of the command line, if present
if (args.length >= 1)
port = Integer.parseInt(argv[0]);
else
port = 0;
// Get the client connection class from the command line, if present
if (args.length >= 2)
{
connectClass = loader.loadClass(argv[1]);
try
{
clientType = (ClientConnection)connectClass.newInstance();
}
catch (ClassCastException e)
{
System.out.println("Given class name " + argv[1]
+ " not a ClientConnection subclass. Using default.");
clientType = new DummyClientConnection();
}
}
else
clientType = new DummyClientConnection();
// Connect a server to the port, and set the client type.
GenServer gs = new GenServer(port);
gs.setConnectionType(clientType);
gs.run();