You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Main.java 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package com.uqac.rthoni.java_rmi;
  2. import java.io.PrintStream;
  3. /**
  4. * Created by robin on 9/15/16.
  5. */
  6. public class Main {
  7. public static void usage(String name, boolean error)
  8. {
  9. PrintStream printStream = (error ? System.err : System.out);
  10. printStream.println("Usage:");
  11. printStream.println(String.format("%1s server port source_dir class_dir log_file", name));
  12. printStream.println("\tPut the program in server mode");
  13. printStream.println("\tport: the port to listen on [1-65535]");
  14. printStream.println("\tsource_dir: the folder to search for java files");
  15. printStream.println("\tclass_dir: the folder to build java files");
  16. printStream.println("\tlog_file: the file to log events");
  17. printStream.println(String.format("%1s client hostname port input_file output_file", name));
  18. printStream.println("\tPut the program in client mode");
  19. printStream.println("\thost: the remote server ip or hostname");
  20. printStream.println("\tport: the port to connect on [1-65535]");
  21. printStream.println("\tinput_file: the command file to use");
  22. printStream.println("\toutput_file: the file to output command results");
  23. printStream.println(String.format("%1s --help", name));
  24. printStream.println(String.format("%1s -h", name));
  25. printStream.println("\tPrint this help and exit");
  26. if (error) {
  27. System.exit(64);
  28. }
  29. }
  30. private static int getPort(String name, String str) {
  31. int port = 0;
  32. try {
  33. port = Integer.parseInt(str);
  34. } catch (Exception e) {
  35. usage(name, true);
  36. }
  37. if (port < 1 || port > 65535) {
  38. usage(name, true);
  39. }
  40. return port;
  41. }
  42. public static void main(String[] args)
  43. {
  44. String name = "java-rmi";
  45. for (String arg : args) {
  46. if (arg.equals("--help") || arg.equals("-h")) {
  47. usage(name, false);
  48. }
  49. }
  50. if (args.length != 5) {
  51. usage(name, true);
  52. }
  53. String mode = args[0];
  54. if (mode.equals("server")) {
  55. int port = getPort(name, args[1]);
  56. String sourceDir = args[2];
  57. String classDir = args[3];
  58. String logFile = args[4];
  59. System.out.println("Hello World! server");
  60. }
  61. else if (mode.equals("client")) {
  62. String host = args[1];
  63. int port = getPort(name, args[2]);
  64. String inputFile = args[3];
  65. String outputFile = args[4];
  66. System.out.println("Hello World! client");
  67. }
  68. else {
  69. usage(name, true);
  70. }
  71. System.exit(0);
  72. }
  73. }