lpr-b-2007-2008:clientecc
package ccRMI; import java.net.MalformedURLException; import java.rmi.Naming; import java.rmi.NotBoundException; import java.rmi.RemoteException; public class Client { /** * @param args */ public static void main(String[] args) { if(args.length==0) { System.out.println("java Client hostRMI nomeOggetto [s|v|p] [somma]"); return; } InterfacciaCC icc = null; try { String rmiUrl = "rmi://"+args[0]+":"+Pubblicatore.porta+"/"+args[1]; System.out.println("Lookup di "+rmiUrl); icc = (InterfacciaCC) Naming.lookup(rmiUrl); } catch (MalformedURLException e) { e.printStackTrace(); return; } catch (RemoteException e) { e.printStackTrace(); return; } catch (NotBoundException e) { e.printStackTrace(); return; } switch (args[2].charAt(0)) { case 's': { // saldo try { System.out.println("Il saldo è "+icc.saldo()); } catch (RemoteException e) { e.printStackTrace(); } break; } case 'p': { // prelievo try { long saldo = icc.prelievo(Integer.parseInt(args[3])); if(saldo < 0) { System.out.println("Operazione fallita; saldo = "+(-saldo)); } else { System.out.println("Operazione avvenuta; saldo = "+saldo); } } catch (NumberFormatException e) { e.printStackTrace(); } catch (RemoteException e) { e.printStackTrace(); } break; } case 'v': { // versamento try { long saldo = icc.versa(Integer.parseInt(args[3])); System.out.println("Operazione avvenuta; saldo = "+saldo); } catch (NumberFormatException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (RemoteException e) { // TODO Auto-generated catch block e.printStackTrace(); } break; } default: { System.out.println("Operazione non riconosciuta"); return; } } System.out.println("Fine operazione"); } }
lpr-b-2007-2008/clientecc.txt · Ultima modifica: 19/09/2008 alle 14:08 (16 anni fa) da 127.0.0.1