⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 calculatorclient.java

📁 同样是软件体系结构RMI方面的例子,对于学习RMI的有一定帮助
💻 JAVA
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -