View Javadoc

1   package fr.ove.clientserver;
2   
3   import java.io.IOException;
4   import fr.ove.clientserver.*;
5   
6   /***
7   *
8   */
9   public class EchoServer {
10      /***
11      * The server.
12      */
13      private Server server;
14      
15      /***
16      * The constructor.
17      * @param portNumber the port number used on the host to run the server (instance).
18      * @param maxSocket the maximum number of connections allowed to the server (instance).
19      */
20      public EchoServer(int portNumber, int maxConnection) throws IOException {
21          server = new Server(portNumber, maxConnection);
22          server.setConnectionHandler(new EchoConnectionHandler());
23      }
24      
25      private static void usage() {
26          System.out.println("java fr.ove.clientserver.EchoServer [portNumber]");
27      }
28      
29      public static void main(String args[]) {
30          EchoServer eServer;
31          try {
32          	switch (args.length) {
33          		case 1 :
34          			try {
35          				eServer = new EchoServer(Integer.parseInt(args[0]), 300);
36          			} catch (NumberFormatException nfe) {
37          				System.err.println(nfe.getMessage());
38          				nfe.printStackTrace(System.err);
39          				usage();
40          			}
41          			break;
42          		case 0 :
43          			eServer = new EchoServer(8080, 300);
44          			break;
45          		default :
46          			usage();
47          			System.exit(0);
48          	}
49          }
50          catch (IOException ioe) {
51              System.out.println("Failed to run server");
52              ioe.printStackTrace();
53          }
54      }
55  }