001package edu.pdx.cs410J.rmi;
002
003import java.net.*;
004import java.rmi.*;
005
006/**
007 * This class uses RMI to solve the below system of equations:
008 *
009 * <PRE>
010 * 4x1 + 3x2 + x3 = 17
011 * 2x1 - 6x2 + 4x3 = 8
012 * 7x1 + 5x2 + 3x3 = 32
013 * </PRE>
014 *
015 * The server will compute the values of <code>x1</code>,
016 * <code>x2</code>, and <code>x3</code>. 
017 */
018public class EquationClient {
019
020  public static void main(String[] args) {
021    String host = args[0];
022    int port = Integer.parseInt(args[1]);
023
024    if (System.getSecurityManager() == null) {
025      System.setSecurityManager(new RMISecurityManager());
026    }
027
028    String name = "//" + host + ":" + port + "/EquationSolver";
029
030    double[][] A = { { 4.0, 3.0, 1.0 }, 
031                     { 2.0, -6.0, 4.0 },
032                     { 7.0, 5.0, 3.0 } };
033    double[] b = { 17.0, 8.0, 32.0 };
034
035
036    try {
037      EquationSolver solver = 
038        (EquationSolver) Naming.lookup(name);
039      double[] x = solver.solve(A, b);
040
041      StringBuffer sb = new StringBuffer();
042      for (int i = 0; i < x.length; i++) {
043        sb.append(x[i]);
044        sb.append(' ');
045      }
046      System.out.println(sb);
047
048    } catch (RemoteException ex) {
049      ex.printStackTrace(System.err);
050
051    } catch (NotBoundException ex) {
052      ex.printStackTrace(System.err);
053
054    } catch (MalformedURLException ex) {
055      ex.printStackTrace(System.err);
056    }
057
058  }
059
060}