普通方法实现——远程方法调用RMI代码演示
1、spring_RMI01_server服务端
package com.wisezone.service; import java.rmi.Remote;
import java.rmi.RemoteException; public interface IHelloService extends Remote { public String sayHello(String msg) throws RemoteException;
}
package com.wisezone.service.impl; import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject; import com.wisezone.service.IHelloService; public class HelloServiceImpl extends UnicastRemoteObject implements IHelloService{ /**
*
*/
private static final long serialVersionUID = -4174742054186163053L; public HelloServiceImpl() throws RemoteException { } @Override
public String sayHello(String msg) throws RemoteException { System.out.println("服务端接受消息:"+msg);
return "hello,"+msg;
} }
package com.wisezone.test; import java.net.MalformedURLException;
import java.rmi.AlreadyBoundException;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry; import com.wisezone.service.impl.HelloServiceImpl; /**
* 发布顺序:先发布服务端,再发布客户端
* @author 王东海
* @2017年5月1日
*/
public class Publish { public static void main(String[] args) throws RemoteException, MalformedURLException, AlreadyBoundException { //设置端口
LocateRegistry.createRegistry(8888);
Naming.bind("rmi://127.0.0.1:8888/hello", new HelloServiceImpl());
System.out.println("发布成功。。。");
}
}
2、spring_RMI01_client客户端
package com.wisezone.service; import java.rmi.Remote;
import java.rmi.RemoteException; public interface IHelloService extends Remote { public String sayHello(String msg) throws RemoteException;
}
package com.wisezone.test; import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException; import com.wisezone.service.IHelloService; public class Test { public static void main(String[] args) throws MalformedURLException, RemoteException, NotBoundException {
IHelloService helloService = (IHelloService) Naming.lookup("rmi://127.0.0.1:8888/hello");
System.out.println("客户端接受消息:"+helloService.sayHello("This is 5月1号劳动节"));
}
}
发布顺序:先发布服务端,再发布客户端
结果:


普通方法实现——远程方法调用RMI代码演示的更多相关文章
- Spring框架实现——远程方法调用RMI代码演示
1.spring_RMI02_server服务端02 <?xml version="1.0" encoding="UTF-8"?> <bean ...
- 远程服务调用RMI框架 演示,和底层原理解析
远程服务调用RMI框架: 是纯java写的, 只支持java服务之间的远程调用,很简单, // 接口要继承 Remote接口 public interface IHelloService extend ...
- Java RMI 远程方法调用
Java RMI 指的是远程方法调用 (Remote Method Invocation).它是一种机制,能够让在某个 Java 虚拟机上的对象调用另一个 Java 虚拟机中的对象上的方法.可以用此方 ...
- SpringBoot里使用RMI进行远程方法调用
一.Java RMI定义 Java RMI:Java远程方法调用,即Java RMI(Java Remote Method Invocation)是Java编程语言里,一种用于实现远程过程调用的应用程 ...
- RMI远程方法调用
RMI远程方法调用:适用于 客户端 调用 服务器 内的方法:(Kotlin 语言编写) 如果业务为二个服务器之间的通信,还是得用消息队列的形式,因为RMI 不适合 双向 调用 下面介绍RMI 的使用方 ...
- Java APi 之 RMI远程方法调用
一.什么是RPC RPC全称是remote procedure call,即远程过程调用.它是一种协议,用于从远程计算机上请求服务. 例如有两台服务器A和B,A上的应用想要调用B上应用的方法,但是他们 ...
- Java RMI远程方法调用
RMI(远程接口调用) 1. RMI的原理: RMI系统结构,在客户端和服务器端都有几层结构. 方法调用从客户对象经占位程序(Stub).远程引用层(Remote Reference Layer)和传 ...
- 简单实现Java的RMI——远程方法调用
一.RMI简介: 说到RMI就不得不说RPC了. RPC:(Remote Procedure Call),远程过程调用. RMI(Remote Method Invocation),远程方法调用. R ...
- 【Java Web开发学习】远程方法调用RMI
Java RMI 远程方法调用Remote Method Invocation 转载:http://www.cnblogs.com/yangchongxing/p/9078061.html 1.创建远 ...
随机推荐
- POJ 3468 A Simple Problem with Integers 【线段树】
题目链接 http://poj.org/problem?id=3468 思路 线段树 区间更新 模板题 在赋初始值的时候,按点更新区间就可以 AC代码 #include <cstdio> ...
- gzframework开发记录
修改窗体权限: 重写方法 修改操作按钮名称 全部自定义增加操作按钮: 插入控件顺序: InsertAfterButton插入到指定控件后面 InsertBeforeButton插入到指定控件前面 公共 ...
- iMX6 yocto平台QT交叉编译环境搭建
转:https://blog.csdn.net/morixinguan/article/details/79351909 . /opt/fsl-imx-fb/4.9.11-1.0.0/environm ...
- Django框架之HTTP本质
1.Http请求本质 浏览器(socket客户端): socket.connect(ip,端口) socket.send("http://www.xiaohuar.com/index.htm ...
- Go Log模块生成日志文件
使用log模块示例代码: package main import ( "fmt" "time" "log" "os" ) ...
- LeetCode——max-points-on-a-line
Question Given n points on a 2D plane, find the maximum number of points that lie on the same straig ...
- Oralce查询后修改数据,弹窗报提示these query result are not updateable,include the ROWID to get updateable
select t.*, (select a.ANNEXNAME from base_annex a where a.id = t.closeFile) closeFileName, (select a ...
- Spring初学之FactoryBean配置Bean
实体bean: Car.java: package spring.beans.factorybean; public class Car { private String name; private ...
- hdu 5904 LCIS dp
LCIS Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem Des ...
- Compaction介绍
Compaction介绍 Compaction是buffer->flush->merge的Log-Structured Merge-Tree模型的关键操作,主要起到如下几个作用: 1)合并 ...