calculatorclient.java

来自「同样是软件体系结构RMI方面的例子,对于学习RMI的有一定帮助」· Java 代码 · 共 41 行

JAVA
41
字号
package test.rmi.client;

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

public class CalculatorClient {
	public static void main(String[]  args)
	   {
	      // set the security manager for the client
	      System.setSecurityManager(new RMISecurityManager());
	      //get the remote object from the registry
	      try
	        {
	          //System.out.println("Security Manager loaded");
	          String url = "//localhost/CalculatorSrv";
	          Calculator remoteObject = (Calculator)Naming.lookup(url);
	          System.out.println("Got remote object");
	          //narrow the object down to a specific one
	          //System.out.println("Location: " + System.getProperty("LOCATION"));
	          // make the invocation
		  
	          System.out.println(" 1 + 2 = " +
	               remoteObject.add(1,2) );
	        }
	      catch (RemoteException exc)
	        {
	          System.out.println("Error in lookup: " + exc.toString());
	        }
	      catch (java.net.MalformedURLException exc)
	        {
	          System.out.println("Malformed URL: " + exc.toString());
	        }
	      catch (java.rmi.NotBoundException exc)
	        {
	          System.out.println("NotBound: " + exc.toString());
	        }
	   }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?