java RMI
import java.rmi.*;
public interface Hello extends Remote {
public String getGreeting() throws RemoteException;
}
import java.rmi.*;
import java.rmi.server.*; public class HelloImpl extends UnicastRemoteObject implements Hello { public HelloImpl() throws RemoteException {
// No action needed here.
} public String getGreeting() throws RemoteException {
return ("Hello there!");
}
}
import java.rmi.*;
public class HelloServer {
private static final String HOST = "localhost";
public static void main(String[] args) throws Exception {
// Create a reference to an
// implementation object
HelloImpl temp = new HelloImpl();
// Create the string URL holding the
// object's name
String rmiObjectName = "rmi://" + HOST + "/Hello";
// (Could omit host name here, since 'localhost'
// would be assumed by default.)
// 'Bind' the object reference to the name
Naming.rebind(rmiObjectName, temp);
// Display a message so that we know the process
// has been completed
System.out.println("Binding complete…\n");
}
}
import java.rmi.*;
public class HelloClient {
private static final String HOST = "localhost";
public static void main(String[] args) {
try {
// Obtain a reference to the object from the
// registry and typecast it into the appropriate
// type
Hello greeting = (Hello) Naming.lookup("rmi://" + HOST + "/Hello");
// Use the above reference to invoke the remote
// object's method
System.out.println("Message received: " + greeting.getGreeting());
} catch (ConnectException conEx) {
System.out.println("Unable to connect to server!");
System.exit();
} catch (Exception ex) {
ex.printStackTrace();
System.exit();
}
}
}
编译运行用到的命令
note javac Hello.java
javac HelloImpl.java
javac HelloServer.java
javac HelloClient.java //This would generate both a stub fi le and a skeleton fi le. However, this stage is no
//longer required
rmic HelloImpl //Starting the RMI registry
rmiregistry //start server
java HelloServer //start client
java HelloClient //result
"Hello there!"
java RMI的更多相关文章
- Exception thrown by the agent : java.rmi.server.ExportException: Port already in use
今天有个应用一直起不来,感觉配置都对啊,奇了怪了.看日志发现如下: STATUS | wrapper | 2017/01/04 08:09:31 | Launching a JVM...INFO | ...
- Java RMI之HelloWorld篇
Java RMI 指的是远程方法调用 (Remote Method Invocation).它是一种机制,能够让在某个 Java 虚拟机上的对象调用另一个 Java 虚拟机中的对象上的方法.可以用此方 ...
- 启动tomcat时 错误: 代理抛出异常 : java.rmi.server.ExportException: Port already in use: 1099;
错误: 代理抛出异常 : java.rmi.server.ExportException: Port already in use: 1099; nested exception is: java ...
- JAVA RMI 实例
下面我将介绍一个完整的实例,让初学者能快速体验RMI的功用. 分为以下四个步骤 1. 创建远程接口及声明远程方法(HelloInterface.java)2. 实现远程接口及远程方法(继承Unicas ...
- JAVA RMI例子
RMI 是java语言的一个RPC框架,本文给出基础例子如下: 1.实现接口: public interface ICalc extends Remote { public int add(int p ...
- java.rmi.NoSuchObjectException: no such object in table
jmx链接的时候,最简单的例子都行不通,郁闷,出现了: 参考:http://reiz6153.blog.163.com/blog/static/401089152009442723208/ 代码: M ...
- 启动tomcat时 错误: 代理抛出异常 : java.rmi.server.ExportException: Port already in use: 1099的解决办法
一.问题描述 今天一来公司,在IntelliJ IDEA 中启动Tomcat服务器时就出现了如下图所示的错误:
- Java RMI 介绍和例子以及Spring对RMI支持的实际应用实例
RMI 相关知识 RMI全称是Remote Method Invocation-远程方法调用,Java RMI在JDK1.1中实现的,其威力就体现在它强大的开发分布式网络应用的能力上,是纯Java的网 ...
- Java学习笔记(十六)——Java RMI
[前面的话] 最近过的好舒服,每天过的感觉很充实,一些生活和工作的技巧注意了就会发现,其实生活也是可以过的如此的有滋有味,满足现在的状况,并且感觉很幸福. 学习java RMI的原因是最近在使用dub ...
- JAVA RMI helloworld入门
Java RMI 指的是远程方法调用 (Remote Method Invocation).它是一种机制,能够让在某个 Java 虚拟机上的对象调用另一个 Java 虚拟机中的对象上的方法.可以用此方 ...
随机推荐
- Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2) B. Bear and Three Musketeers 枚举
B. Bear and Three Musketeers ...
- SU Demos-03T-F Analysis-02Sutvband
第一个脚本,生成震源扫描信号,并进行gabor变换 运行结果, 第二个脚本,利用时变滤波从和信号中重建单独的3个扫描信号 运行结果
- 枚举 POJ 1753 Flip Game
题目地址:http://poj.org/problem?id=1753 /* 这题几乎和POJ 2965一样,DFS函数都不用修改 只要修改一下change规则... 注意:是否初始已经ok了要先判断 ...
- Codeforces Round #292 (Div. 2)
A. Drazil and Date 无算法,判断(s - (a + b)) % 2是否为零,若零,表示在s步内还能走向其他的地方并且回来 否则,都是No #include <cstdio> ...
- windows 8 系统部署IIS并发布网站
企业用户可以在已经部署了windows 8 的电脑中通过部署IIS服务器来发布自己公司的企业内部网站实现对企业的网络办公的管理工作. 准备篇 IIS的添加和运行 一.IIS的添加 1.请进入“控制面板 ...
- unity button
#pragma strict var buttonTexture:Texture2D; private var str:String; private var frameTime:int; funct ...
- extjs grid
Ext.onReady(function() { Ext.BLANK_IMAGE_URL = '../resources/images/default/s.gif'; Ext.QuickTips.in ...
- 【BZOJ】2463: [中山市选2009]谁能赢呢?(博弈论)
http://www.lydsy.com/JudgeOnline/problem.php?id=2463 好神的证明! 首先对于n是偶数,一定能被1*2的骨牌覆盖!所以从起点开始,先手一定走的是骨牌的 ...
- 泛型,动态创建List<T> (转摘)
第一种: static void Main() { object intList = MakeList(typeof(int), 1, 2, 3); ...
- myeclipse 8.5最新注册码
myeclipse 8.5最新注册码(过期时间到2016年) Subscriber:huazai Subscription Code:uLR8ZC-855550-6156585630 ...