Rmi Hello World (实践rmi)
2017-01-06 12:18
323 查看
package com.xiuye.rmi; import java.rmi.Remote; import java.rmi.RemoteException; public interface IHello extends Remote { /** * java.rmi.server.ExportException: remote object implements illegal remote * interface; nested exception is: java.lang.IllegalArgumentException: * illegal remote method encountered: public abstract java.lang.String * com.xiuye.rmi.IHello.helloworld() at * sun.rmi.server.UnicastServerRef.exportObject(UnicastServerRef.java:203) * at java.rmi.server.UnicastRemoteObject.exportObject(UnicastRemoteObject. * java:383) at * java.rmi.server.UnicastRemoteObject.exportObject(UnicastRemoteObject * .java:320) at * java.rmi.server.UnicastRemoteObject.<init>(UnicastRemoteObject.java:198) * at * java.rmi.server.UnicastRemoteObject.<init>(UnicastRemoteObject.java:180) * at com.xiuye.rmi.HelloWorldRmi.<init>(HelloWorldRmi.java:13) at * com.xiuye.rmi.IHelloServer.main(IHelloServer.java:13) Caused by: * java.lang.IllegalArgumentException: illegal remote method encountered: * public abstract java.lang.String com.xiuye.rmi.IHello.helloworld() at * sun.rmi.server.Util.checkMethod(Util.java:267) at * sun.rmi.server.Util.getRemoteInterfaces(Util.java:246) at * sun.rmi.server.Util.getRemoteInterfaces(Util.java:216) at * sun.rmi.server.Util.createProxy(Util.java:146) at * sun.rmi.server.UnicastServerRef.exportObject(UnicastServerRef.java:201) * ... 6 more * * * * @return * @throws RemoteException */ public String helloworld() throws RemoteException;// 必须抛出remote异常,否则报错: }
package com.xiuye.rmi;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
public class HelloWorldRmi extends UnicastRemoteObject implements IHello {
/**
*
*/
private static final long serialVersionUID = -5537185508353408293L;
protected HelloWorldRmi() throws RemoteException {
}
@Override
public String helloworld() {
return "HelloWorld!";
}
}
package com.xiuye.rmi;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
public class IHelloServer {
public static void main(String[] args) {
try {
IHello hello = new HelloWorldRmi();
LocateRegistry.createRegistry(9999);
// Naming.rebind("rmi://localhost:9999/hello", hello);
Naming.rebind("//localhost:9999/hello", hello);
System.out.println("wait for client coming!");
} catch (RemoteException e) {
e.printStackTrace();
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
}
wait for client coming!
package com.xiuye.rmi; import java.net.MalformedURLException; import java.rmi.Naming; import java.rmi.NotBoundException; import java.rmi.RemoteException; public class IHelloClient { public static void main(String[] args) { try { IHello hello = (IHello) Naming.lookup("//localhost:9999/hello"); System.out.println(hello.helloworld()); } catch (MalformedURLException | RemoteException | NotBoundException e) { e.printStackTrace(); } } }
HelloWorld!
相关文章推荐
- flashremoting实践(二)-hello world for .net
- java HelloWorld 编程风格实践
- flashremoting实践(三)-hello world for java
- Java RMI HelloWorld
- Spring整合使用RMI-HelloWorld例子
- 操作系统实践之第一章(Hello OS world)
- 《深入理解OSGi:Equinox原理、应用与最佳实践》笔记_1_运行最简单的bundlehelloworld
- 《深入理解OSGi:Equinox原理、应用与最佳实践》笔记_1_运行最简单的bundlehelloworld
- Spring Boot实践教程(一):Hello,world!
- [转]flashremoting实践(二)-hello world for .net
- Java RMI helloworld
- 字符设备驱动之"Hello, World!"
- (二).SpringMVC 学习-SpringMVC Hello World!
- Qt tutorial 1 -- hello,world
- Docker Hello World
- Lucene helloworld
- WF 4.0: Building a Hello World Sequential Workflow
- 解剖Nginx·模块开发篇(2)ngx_http_hello_world_module 模块基本结构定义
- C#免费IDE sharpdevelop 初探之二 Hello,world
- Red5 第一个例子之HelloWorld