远程方法调用(RML)
来源:互联网 发布:免费淘宝代码 编辑:程序博客网 时间:2024/06/06 09:56
File Server.java
import java.rmi.registry.Registry;
import java.rmi.registry.LocateRegistry;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
public class Server implements Hello {
public Server() {}
public String sayHello() {
return "Hello, world!";
}
public static void main(String args[]) {
try {
Server obj = new Server();
Hello stub = (Hello)UnicastRemoteObject.exportObject(obj, 0);
// Bind the remote object's stub in the registry
Registry registry = LocateRegistry.getRegistry();
registry.bind("Hello", stub);
System.err.println("Server ready"); }
catch (Exception e) {
System.err.println("Server exception: " + e.toString());
e.printStackTrace();
}
}
}
Client.java
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
public class Client {
private Client() {}
public static void main(String[] args) {
String host = (args.length < 1) ? null : args[0];
try {
System.out.println("Host: " + host);
Registry registry = LocateRegistry.getRegistry(host);
Hello stub = (Hello) registry.lookup("Hello");
String response = stub.sayHello();
System.out.println("response: " + response); }
catch (Exception e) {
System.err.println("Client exception: " + e.toString());
e.printStackTrace();
}
}
}
File Hello.java
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface Hello extends Remote {
String sayHello() throws RemoteException;
}
Task 1
To compile the above hello world application one can use the standard: javac *.java to compile all the files. Before the applications can be run, the rmiregistry must be running so that remote objects may be registered. Open a prompt and enter one of the following:
rmiregistry (to run within that window), start rmiregistry (to run within a new window)
To run the Server: start java Server
To run the Client: java Client
- 远程方法调用(RML)
- RML(Riemann流形学习)
- RMI(远程方法调用)
- 远程方法调用(RMI)
- 远程方法调用(RMI)机制
- 远程方法调用(RMI)机制
- rmi(远程方法调用)入门概述
- Java远程方法调用(RMI)(转)
- Java远程方法调用(RMI)机制
- Java RMI 框架(远程方法调用)
- java远程方法调用(RMI)
- Java远程方法调用(RMI)
- java远程方法调用(java RMI)
- java远程方法调用(简单入门)
- Java RMI 框架(远程方法调用)
- ava RMI 框架(远程方法调用)
- Java RMI 框架(远程方法调用)
- Java RMI 框架(远程方法调用)
- 数据类型之间的转换
- Eclipse中tomcat启动不了
- CentOS VI常用命令
- D3D11的纹理寻址模式
- SAR学习
- 远程方法调用(RML)
- node.js 后台解析数据
- python中的元类Metaclass
- Zookeeper:Curator框架应用和常用命令
- Dubbo消费端java.lang.NoClassDefFoundError错误的排查
- 【HDU5895【公式转化 矩阵快速幂 欧拉定义】Mathematician QSC 递推数列前n平方项和 (转)
- NOIP专题复习——专题二:动态规划基础
- gdb调试线程
- 如何解压deb 包;