Ejemplo n.º 1
0
 /**
  * @param args String array containing Program arguments. It should only contain at most one
  *     String indicating the port it should connect to. The String should be parseable into an
  *     int. If no arguments, we default to port 4444.
  */
 public static void main(String[] args) throws IOException {
   if (args.length > 1) {
     System.err.println(
         "Usage: java EchoServer [port], where port is an optional\n"
             + " numerical argument within range 0-65535.");
     System.exit(1);
   }
   int port = 0;
   if (args.length == 0) {
     port = ECHO_PORT;
   } else if (args.length == 1) {
     try {
       port = Integer.parseInt(args[0]);
     } catch (NumberFormatException nfe) {
       // complain about ill-formatted argument
       System.err.println("EchoServer: illegal port, " + args[0]);
       nfe.printStackTrace();
     }
   }
   try {
     EchoServer server = new EchoServer(port);
     server.serve();
   } catch (IOException ioe) {
     ioe.printStackTrace();
   }
 }
Ejemplo n.º 2
0
 /*
  * Connect server without an argument
  */
 @Test
 public void TestServer1() throws IOException {
   EchoServer.main();
 }
Ejemplo n.º 3
0
 public void TestServer() throws IOException {
   String[] strings = new String[1];
   strings[0] = "4949";
   EchoServer.main(strings);
 }