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 PipeServer {
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      * @param hostName the name of the host the instance connects to.
20      * @param dportNumber the port number through the instance is connected.
21      */
22      public PipeServer(int portNumber, int maxConnection, String hostName, int dportNumber) throws IOException {
23          server = new Server(portNumber, maxConnection);
24          server.setConnectionHandler(new PipeConnectionHandler(hostName, dportNumber));
25      }
26      
27      public static void main(String args[]) {
28          PipeServer pServer;
29          try {
30          	switch (args.length) {
31          		case 3 :
32          			try {
33          				pServer = new PipeServer(Integer.parseInt(args[0]), 300, args[1], Integer.parseInt(args[2]));
34          			} catch (NumberFormatException nfe) {
35          				System.err.println(nfe.getMessage());
36          				nfe.printStackTrace(System.err);
37          				usage();
38          			}
39          			break;
40          		case 0 :
41          			pServer = new PipeServer(6666, 300, "localhost", 8080);
42          			break;
43          		default :
44          			usage();
45          			System.exit(0);
46          	}
47          }
48          catch (IOException ioe) {
49              System.out.println("Failed to run server");
50              ioe.printStackTrace();
51          }
52      }
53      
54      private static void usage() {
55          System.out.println("java fr.ove.clientserver.PipeServer [portNumber serverName serverPortNumer]");
56      }
57  }