📄 calculatorclient.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 + -