1 package client;
2 
3 import java.io.InputStreamReader;
4 import java.io.BufferedReader;
5 import common.RemoteBank;
6 import common.RemoteLoginServer;
7 import java.rmi.Naming;
8 import java.io.BufferedReader;
9 import java.io.InputStreamReader;
10import org.jstk.example.bank.client.BankClient;
11import javax.security.auth.login.LoginException;
12
13public class RMIBCShell {
14    public static void main(String[] args) throws Exception {
15
16        BankClient bc = new BankClient();
17        RemoteLoginServer rls = (RemoteLoginServer)Naming.lookup("rmi://" + args[0] + "/" + "MyRemoteLoginServer");
18
19        // Prompt for username and password
20        System.out.print("login: ");
21        System.out.flush();
22        String username = new BufferedReader(new InputStreamReader(System.in)).readLine();
23        System.out.print("password: ");
24        System.out.flush();
25        String password = new BufferedReader(new InputStreamReader(System.in)).readLine();
26
27        RemoteBank rbank = null;
28        try {
29            rbank = rls.login(username, password);
30        } catch (LoginException le){
31            System.out.println("Login Failed. " + le.getMessage());
32            return;
33        }
34        bc.init(new BankProxy(rbank));
35        while (true){
36            System.out.print("rbcsh>");
37            System.out.flush();
38            String cmdline = new BufferedReader(new InputStreamReader(System.in)).readLine();
39            String[] cmdargs = cmdline.split("\\s");
40
41            String result = bc.execCommand(cmdargs);
42            System.out.println(result);
43        }
44    }
45}