配置RMI主机,以便它应该知道哪个客户端端口正在访问它 [英] configuring RMI host so that it should know which client port is accessing it

查看:144
本文介绍了配置RMI主机,以便它应该知道哪个客户端端口正在访问它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在从事Spring RMI的工作,并设置了一个主机和一个客户端.

I have been working on spring RMI and I have set up a host and one client.

下面是我的主机的代码.我想通过主机应该知道哪个客户端正在访问它的方式来修改它,换句话说,服务器应该知道哪个客户端端口正在访问它.

Below is the code of my host. I want to modify it in such a way that host should know which client is accessing it, so in other words server should know which client port is accessing it.

如何在Spring RMI中实现这一目标?

How can I achieve this in Spring RMI?

界面:-

package com.javatpoint;  

public interface Calculation {  
int cube(int number);  
}  

课程:-

package com.javatpoint;  

public class CalculationImpl implements Calculation{  

    @Override  
    public int cube(int number) {  
        return number*number*number;  
    }  

}  

最后是主机配置 xml

<?xml version="1.0" encoding="UTF-8"?>  
<beans xmlns="http://www.springframework.org/schema/beans"  
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
    xsi:schemaLocation="http://www.springframework.org/schema/beans   
http://www.springframework.org/schema/beans/spring-beans.xsd">  

<bean id="calculationBean" class="com.javatpoint.CalculationImpl"></bean>  
<bean class="org.springframework.remoting.rmi.RmiServiceExporter">  
    <property name="service" ref="calculationBean"></property>  
    <property name="serviceInterface" value="com.javatpoint.Calculation"></property>  
    <property name="serviceName" value="CalculationService"></property>  
    <property name="replaceExistingBinding" value="true"></property>  
    <property name="registryPort" value="1099"></property>  
</bean>  
</beans>  

以下是我使用的类

界面:-

package com.javatpoint;

public interface Calculation {
int cube(int number);
}

实施类:-

public class CalculationImpl implements Calculation{

    public int cube(int number) {
        return number*number*number;
    }

}

主班

package com.javatpoint;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Host
{
    public static void main(String[] args)
    {
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        System.out.println("Waiting for requests");

    }
}

现在,请告知如何添加获取客户端主机的方法.

now please advise how to add the method get client host Thanks in advance

推荐答案

配置RMI主机,以便它应该知道哪个客户端端口正在访问它

configuring RMI host so that it should know which client port is accessing it

  1. 没有RMI主机的配置"将传递该信息.

  1. There is no 'configuration' of the RMI host that will deliver that information.

客户端端口信息完全没有用.

The client port information is completely and utterly useless.

  • 它不是每个客户唯一的.
  • 它不是每个客户都固定的.
  • 它可以并且将在客户的整个生命周期内发生变化.

对我来说,这听起来像是远程会话模式的案例.

It sounds like a case for the Remote Session Pattern to me.

这篇关于配置RMI主机,以便它应该知道哪个客户端端口正在访问它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆