2012-04-23 25 views
0

私はRMI電卓プログラムをコーディングしています。私は以下の.javaファイルを作成しました。ガイドラインに沿って、私はサービスアプリケーションを実行する必要があるようになった。これを行うには、私はRMI電卓の問題(JAVA)

開始するrmiregistry

を入力して、新しい空白のウィンドウが開きます。私は、次のように入力して、電卓サービスを開始しよう:

JavaのCalculatorService

、その後何も起こりません。

私のガイドラインは、「私は、サーバーが格納されているディレクトリと同じディレクトリからレジストリを確実に実行する必要があります。

あなたはこれで私を助けることができると思いますか? ここにすべての私のコードです:

Calculator.java

import java.rmi.Remote; 
import java.rmi.RemoteException; 

public interface Calculator extends java.rmi.Remote 
{ 
    /* 
    * method for addition 
    */ 
    public double add(double x, double y) 
      throws RemoteException; 

    /* 
    * method for subtraction 
    */ 
    public double subtract(double x, double y) 
      throws RemoteException; 
    /* 
    * method for multiplication 
    */ 
    public double multiply(double x, double y) 
      throws RemoteException; 
    /* 
    * method for division 
    */ 
    public double divide(double x, double y) 
      throws RemoteException; 
} 

RemoteCalculator.java

import java.rmi.server.UnicastRemoteObject; 
import java.rmi.RemoteException; 
public class RemoteCalculator extends UnicastRemoteObject implements Calculator 
{ 
    public RemoteCalculator() throws RemoteException 
    { 

    } 

    /* 
    * method for addition 
    */ 
    public double add(double x, double y) 
    { 
     return x+y; 
    } 
    /* 
    * method for subtraction 
    */ 
    public double subtract(double x, double y) 
    { 
     return x-y; 
    } 
    /* 
    * method for multiplication 
    */ 
    public double multiply(double x, double y) 
    { 
     return x*y; 
    } 
    /* 
    * method for division 
    */ 
    public double divide(double x, double y) 
    { 
     return x/y; 
    } 
} 

CalculatorService.java

import java.rmi.Naming; 
import java.rmi.RemoteException; 
import java.rmi.RMISecurityManager; 

public class CalculatorService 
{ 
    public static void main(String[] args) throws RemoteException,java.net.MalformedURLException 
    { 
     RemoteCalculator remcalc = new RemoteCalculator(); 
     Naming.rebind("CalcService", remcalc); 

    } 
} 

CalculatorClient.java

import java.rmi.Naming; 
public class CalculatorClient 
{ 
    public static void main(String[] args) 
    { 
     double x = Double.parseDouble(args[1]); 
     double y = Double.parseDouble(args[2]); 
     try 
     { 
      //Connect to the calculator service 
      Calculator calc = (Calculator) Naming.lookup("rmi://" + args[0] + "/CalcService"); 
      System.out.println("Client bound: OK"); 
      //Add the numbers 
      System.out.println(x + " + " + y + " = " + calc.add(x, y)); 
      //Subtract the numbers 
      System.out.println(x + " - " + y + " = " + calc.subtract(x, y)); 
      //Multiply the numbers 
      System.out.println(x + " * " + y + " = " + calc.multiply(x, y)); 
      //Divide the numbers 
      System.out.println(x + "/" + y + " = " + calc.divide(x, y)); 

     } 
     catch (java.rmi.NotBoundException nbe) 
     { 
      System.out.println("Client bound: error: " + nbe); 
     } 
     catch (java.net.MalformedURLException mue) 
     { 
      System.out.println("Client bound: error: " + mue); 

     } catch (java.rmi.RemoteException re) 
     { 

     } 

    } 
} 
+0

*何も起こりませんか?例外なく?そして何が起こると思いますか? – EJP

答えて

0

ここに手順があります。

  1. コンパイルjavacの使用
  2. はrmicコンパイラでコンパイルし
  3. 開始するrmiregistry
  4. 開始サーバ
  5. あなたはSTEP2をしました開始クライアント

  • +0

    はい私はRemoteCalculator.javaをコンパイルした後それをコンパイルしました: 'rmic RemoteCalculator' –