当前位置: 首页 > news >正文

htm5网站建设在什么网站可以免费

htm5网站建设,在什么网站可以免费,成都网站建设新网创想,外贸网站怎么做外链参考其它rmi(remote method invocation)的代码后,加入了自己思考。整个工程基于maven构建,我觉得maven的模块化可比较直观地演示rmi 目录 项目结构图 模块解读 pom文件 rmi-impl rmi-common-interface rmi-server rmi-cli…

参考其它rmi(remote method invocation)的代码后,加入了自己思考。整个工程基于maven构建,我觉得maven的模块化可比较直观地演示rmi

目录

项目结构图

模块解读

pom文件

rmi-impl

rmi-common-interface

rmi-server

rmi-client

 各模块源码

rmi-common-interface

RemoteInterface.java

rmi-server

RMIServer.java

RMIServerProperties.java

rmi-client

 RMIClient.java

 启动说明(重要)

运行截图

启动服务是的控制台信息

​编辑客户端连接服务端并发送消息

服务端控制台再次打印信息


项目结构图

模块解读

整个工程rmi-impl分为三个子模块

1、rmi-commom-interface:rmi-server与rmi-client都依赖的模块,用来定义供服务端实现、供客户端调用的公共远程调用接口

2、rmi-server:实现远程调用接口,并注册服务

3、rmi-client:拉去服务,并调用远程接口

pom文件

rmi-impl

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>psn.kiko</groupId><artifactId>rmi-impl</artifactId><packaging>pom</packaging><version>1.0-SNAPSHOT</version><modules><module>rmi-common-interface</module><module>rmi-server</module><module>rmi-client</module></modules><properties><maven.compiler.source>8</maven.compiler.source><maven.compiler.target>8</maven.compiler.target></properties></project>

rmi-common-interface

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><parent><artifactId>rmi-impl</artifactId><groupId>psn.kiko</groupId><version>1.0-SNAPSHOT</version></parent><modelVersion>4.0.0</modelVersion><artifactId>rmi-common-interface</artifactId><properties><maven.compiler.source>8</maven.compiler.source><maven.compiler.target>8</maven.compiler.target></properties></project>

rmi-server

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><parent><artifactId>rmi-impl</artifactId><groupId>psn.kiko</groupId><version>1.0-SNAPSHOT</version></parent><modelVersion>4.0.0</modelVersion><artifactId>rmi-server</artifactId><properties><maven.compiler.source>8</maven.compiler.source><maven.compiler.target>8</maven.compiler.target></properties><--依赖common模块--><dependencies><dependency><groupId>psn.kiko</groupId><artifactId>rmi-common-interface</artifactId><version>1.0-SNAPSHOT</version></dependency></dependencies></project>

rmi-client

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><parent><artifactId>rmi-impl</artifactId><groupId>psn.kiko</groupId><version>1.0-SNAPSHOT</version></parent><modelVersion>4.0.0</modelVersion><artifactId>rmi-client</artifactId><properties><maven.compiler.source>8</maven.compiler.source><maven.compiler.target>8</maven.compiler.target></properties><--依赖common模块--><dependencies><dependency><groupId>psn.kiko</groupId><artifactId>rmi-common-interface</artifactId><version>1.0-SNAPSHOT</version></dependency></dependencies>
</project>

 各模块源码

rmi-common-interface

RemoteInterface.java

package psn.kiko.rmi.common;import java.rmi.Remote;
import java.rmi.RemoteException;/*** 声明远程服务接口,此接口里声明的方法,由服务端实现,供客户端调用。* 鉴于此,将所有远程接口都放到common模块,并在需要此接口的模块引入<br>* on 2023/2/15 18:03*/
public interface RemoteInterface extends Remote {/*** 此方法将会在服务端打印message:由rmi-server模块实现,由rmi-client远程调用* @param message* @throws RemoteException*/void printMsg(String message) throws RemoteException;
}

rmi-server

RMIServer.java

package psn.kiko.rmi.server;import psn.kiko.rmi.common.RemoteInterface;import java.net.MalformedURLException;
import java.rmi.AlreadyBoundException;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.server.UnicastRemoteObject;/*** rmi服务端<br>* on 2023/2/15 18:08*/
public class RMIServer extends UnicastRemoteObject implements RemoteInterface {// 运行main注册服务public static void main(String[] args) {try {rmiServerRegistration();} catch (RemoteException | MalformedURLException | AlreadyBoundException e) {e.printStackTrace();}}private RMIServerProperties serverProperties;public void setServerProperties(RMIServerProperties serverProperties) {this.serverProperties = serverProperties;}public RMIServerProperties getServerProperties() {return serverProperties;}protected RMIServer() throws RemoteException {}@Overridepublic void printMsg(String message) throws RemoteException {System.out.println(this.serverProperties.getSeverName()+"获得客户端消息: "+message);}/*** rmi服务注册:添加到虚拟机注册表* @throws RemoteException* @throws AlreadyBoundException* @throws MalformedURLException*/private static void rmiServerRegistration() throws RemoteException, AlreadyBoundException, MalformedURLException {RMIServer rmiServer = new RMIServer();rmiServer.setServerProperties(new RMIServerProperties(8888, "rmi-server"));LocateRegistry.createRegistry(rmiServer.getServerProperties().getServerPort());Naming.bind(rmiServer.getServerProperties().getServerUrl(), rmiServer);System.out.println(rmiServer.getServerProperties().getSeverName()+"已启动================>");}
}

RMIServerProperties.java

 

package psn.kiko.rmi.server;/*** 服务端参数<br>* on 2023/2/15 18:41*/
public class RMIServerProperties {private String serverUrl; //服务端通信地址private int serverPort;//服务端端口private String severName;//服务名称public RMIServerProperties(int serverPort,String serverName) {this.severName=serverName;this.serverPort = serverPort;this.serverUrl ="rmi://localhost:"+serverPort+"/"+severName;}public String getServerUrl() {return serverUrl;}public int getServerPort() {return serverPort;}public String getSeverName() {return severName;}
}

rmi-client

 RMIClient.java

package psn.kiko.client;import psn.kiko.rmi.common.RemoteInterface;import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.util.Scanner;/*** rmi客户端<br>* on 2023/2/15 18:19*/
public class RMIClient {// 运行main获取远程服务,并向其传输messagepublic static void main(String[] args) {try {RemoteInterface rmiServer = (RemoteInterface)Naming.lookup("rmi://localhost:8888/rmi-server");Scanner scanner = new Scanner(System.in);System.out.println("请输入需要发送给服务端的信息=============>");String message = scanner.next();rmiServer.printMsg(message);System.out.println("客户端发送消息完毕<=====================");} catch (NotBoundException | MalformedURLException | RemoteException e) {e.printStackTrace();}}
}

 启动说明(重要)

先运行RMIServer.main(启动后将等待客户端连接),再运行RMIClient.main(可多次单独运行,进行多次连接通信)

运行截图

启动服务是的控制台信息

截图中的红色正方形也表示服务程序启动后就一直运行着

客户端连接服务端并发送消息

灰色正方形表示客户端与服务端通信完毕就断开连接

服务端控制台再次打印信息

红色正方形表示服务端与客户端通信完毕后仍在运行

以上就是全部关于RMI的详细基础用法了

 

 

http://www.dinnco.com/news/32075.html

相关文章:

  • 上海物流网站怎么建设推广营销
  • 成都网站建设外贸google官方入口
  • app软件开发课程成都高新seo
  • 介绍学校网站怎么做怎么简单制作一个网页
  • 手机版网站制作费用郑州网站开发公司
  • 在线客服系统腾讯成都比较靠谱的seo
  • 库存网站建设哪家好国际新闻最新消息2022
  • 高端做网站公司哪家好百度竞价seo排名
  • 免费网站建设阿里云百度关键词搜索技巧
  • 王烨然盈盈北京网站优化排名
  • 建教会网站的内容站内优化seo
  • 如何做网站授权常见的网站推广方法
  • 做网站困难吗百度关键词排名技术
  • 大连比较好的网站公司吗品牌推广宣传词
  • 商城网站后续费用seo优化入门教程
  • 苏州网站营销公司指数分布的期望和方差
  • 江西网站设计团队百度自媒体平台
  • 国家高新技术企业认定标准徐州seo排名收费
  • 梵客家装靠谱吗宁波seo教程app推广
  • 手机网站排名优化软件游戏推广员上班靠谱吗
  • 搏彩网站开发建设友链网站
  • 好的做网站的公司自媒体推广渠道
  • 网站打不开是怎么回事百度竞价优化
  • 网站建设公司权威机构小程序开发模板
  • 代发货网站系统建设视频号推广方法
  • 模板号专注于网站抖音seo怎么做
  • 郑州网站建站网站怎么样网店运营推广方案
  • 北京 响应式网站建设苏州seo网站优化软件
  • wordpress首页设计关键词优化和seo
  • 小橘子被做h网站快速百度