📄 client.java
字号:
/*
* Client application
*/
import javax.rmi.PortableRemoteObject;
import javax.naming.Context;
import javax.naming.InitialContext;
public class Client {
public static void main(String[] args) {
try {
// get the naming context
Context ic = new InitialContext();
// get a reference to the remote object
Object objRef = ic.lookup("Server");
// narrow it into our RMIInterface
RMIInterface ri =
(RMIInterface)PortableRemoteObject.narrow(objRef, RMIInterface.class);
// call the hello method
System.out.println("Recieved from server: "+ri.hello()+"\n");
// now lets try RMI serialization
SerClass se = new SerClass(5, "Client string! ");
// pass the class to be altered on the server
// of course behind the scenes this class is being serialized over IIOP
se = ri.alterClass(se);
// now let's see the result
System.out.println("Serialization results :\n"+
"Integer was 5 now is "+se.getX()+"\n"+
"String was \"Client String! \" now is \""+se.getString()+"\"");
} catch (Exception e) {
e.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -