RMI简单例子
来源:互联网 发布:主机公园 php搭建 编辑:程序博客网 时间:2024/05/16 18:21
1)定义一个接口
public interface HelloInterface extends Remote{
public String sayHello(String name) throws RemoteException;
}
2)实现接口
public class HelloInterfaceImpl extends UnicastRemoteObject implements HelloInterface{
protected HelloInterfaceImpl() throws RemoteException {
}
public String sayHello(String name) throws RemoteException {
String strHello = "你 " + name+" 欢器";
System.out.println(name +" 正 ");
return strHello;
}}
3)启动 server
HelloInterface hInterface = new HelloInterfaceImpl();
int port = 6666
LocateRegistry.createRegistry(port);
String address = "rmi://localhost:" + port + "/hello";
System.out.println("服务端地址: "+address);
Naming.bind(address,hInterface);
System.out.println(">>>服务端成功启动");
4)启动client
int port = 6666;
String address = "rmi://127.0.0.1:" + port + "/hello";
try {
HelloInterface hInterface = (HelloInterface) Naming.lookup(address);
System.out.println("客户端成功启动");
System.out.println(hInterface.sayHello("aaaa"));
} catch (MalformedURLException e) {
public interface HelloInterface extends Remote{
public String sayHello(String name) throws RemoteException;
}
2)实现接口
public class HelloInterfaceImpl extends UnicastRemoteObject implements HelloInterface{
protected HelloInterfaceImpl() throws RemoteException {
}
public String sayHello(String name) throws RemoteException {
String strHello = "你 " + name+" 欢器";
System.out.println(name +" 正 ");
return strHello;
}}
3)启动 server
HelloInterface hInterface = new HelloInterfaceImpl();
int port = 6666
LocateRegistry.createRegistry(port);
String address = "rmi://localhost:" + port + "/hello";
System.out.println("服务端地址: "+address);
Naming.bind(address,hInterface);
System.out.println(">>>服务端成功启动");
4)启动client
int port = 6666;
String address = "rmi://127.0.0.1:" + port + "/hello";
try {
HelloInterface hInterface = (HelloInterface) Naming.lookup(address);
System.out.println("客户端成功启动");
System.out.println(hInterface.sayHello("aaaa"));
} catch (MalformedURLException e) {
- RMI简单例子
- RMI的简单例子
- Java RMI的简单例子
- Java RMI的简单例子
- Java RMI的简单例子
- 最简单的rmi例子
- Spring rmi实现简单例子
- java RMI简单例子+工场模式改进RMI
- RMI例子
- RMI例子
- rmi 例子
- 关于Java的RMI编程的一个简单的例子
- 关于Java的RMI编程的一个简单的例子
- 关于spring 与rmi整合简单例子详解
- Python中实现远程调用(RPC、RMI)简单例子
- 基于RMI实现远程聊天功能的简单例子
- spring rmi 例子
- java rmi例子
- Eclipse3.7中搭建Android开发环境
- 如何通过定时关机命令,实现Windows XP的自动关机?
- linux rootfs 脚本实现 U 盘自动挂载记录
- 如何向领导汇报工作(4)
- Manage objective c object memory in Block
- RMI简单例子
- 动态初始化编号的一种方法
- poj1050 动态规划 求二维数组中子矩阵和的最大值
- hive expecting Identifier near 'table' in table name 报错
- C#中的yield return 和return有什么区别
- Eclipse swing/swt可视化开发工具windowbuilder 搭载
- RTMP协议中的AMF数据
- java中判断字符串是否为数字的三种方法
- jqGrid的使用方法(编辑,删除,更新,新增)