Advertisement
Guest User

Untitled

a guest
Nov 25th, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.97 KB | None | 0 0
  1.     private static void printMenu(){
  2.         System.out.println("Welcome to dropMusic");
  3.         System.out.println("1- Login");
  4.         System.out.println("2- Sign up");
  5.     }
  6.     private static String menu() {
  7.         int opt;
  8.         String msg="";
  9.         Scanner scan = new Scanner(System.in);
  10.         opt = scan.nextInt();
  11.         switch (opt) {
  12.         case 1:
  13.             scan.nextLine();
  14.             String user, pass;
  15.             System.out.println("Username: ");
  16.             user = scan.nextLine();
  17.             System.out.println("Password: ");
  18.             pass = scan.nextLine();
  19.             msg = "type / login ; username / " + user + ";  password / " + pass;
  20.             break;
  21.            
  22.  
  23.         case 2:
  24.             String name,mail;
  25.             scan.nextLine();
  26.             System.out.println("Nome: ");
  27.             name = scan.nextLine();
  28.             System.out.println("Username: ");
  29.             user = scan.nextLine();
  30.             System.out.println("Password: ");
  31.             pass = scan.nextLine();
  32.             System.out.println("Email: ");
  33.             mail = scan.nextLine();
  34.             msg = "type / sign up ; item_count / 3 ; name / " + name +" ; username / "+user+ " ;  password / " + pass+" ; mail / "+mail;
  35.             System.out.println(msg);
  36.             break;
  37.         }
  38.         return msg;
  39.  
  40.     }
  41.  public static void main(String[] args)
  42.             throws MalformedURLException, RemoteException, NotBoundException, IOException {
  43.  
  44.         String line = "";
  45.         line="";
  46.         System.getProperties().put("java.security.policy", "out/production/projeto2/policy.all");
  47.  
  48.         System.setSecurityManager(new RMISecurityManager());
  49.  
  50.         ServerRmiInt si = null;
  51.  
  52.         ClientRmi c = new ClientRmi();
  53.  
  54.         c.setNome(args[0]);
  55.  
  56.         si = (ServerRmiInt) Naming.lookup(nomeServer);
  57.         si.subscribe(args[0], c);
  58.  
  59.         System.out.println("Request sent to Server");
  60.  
  61.         InputStreamReader input = new InputStreamReader(System.in);
  62.         BufferedReader reader = new BufferedReader(input);
  63.         printMenu();
  64.         // entra em ciclo para comunnicacao com o server rmi
  65.         while (true) {
  66.             try {
  67.  
  68.  
  69.                 line = menu();
  70.                 si.sendMulti(line, args[0], c);
  71.  
  72.                 if (line.equals("type / share")) {// comando share para partilhar up/download
  73.                     uploadDownloadTCP();
  74.                 }
  75.             } catch (java.rmi.ConnectException e) {// trata da falha no servidor principal para passar ao backup
  76.                 si = (ServerRmiInt) Naming.lookup(nomeServer);
  77.                 si.subscribe(args[0], c);
  78.                 System.out.println("aqui");
  79.                 si.sendMulti(line, args[0], c);
  80.             } catch (RemoteException re) {
  81.                 System.out.println("Exception remote in main " + re);
  82.             } catch (IOException e) {
  83.                 System.out.println("Exception in main " + e);
  84.             }
  85.         }
  86.     }
  87.  
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement