Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
336 views
in Technique[技术] by (71.8m points)

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

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.

How can I achieve this in Spring RMI?

interface :-

package com.javatpoint;  

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

class :-

package com.javatpoint;  

public class CalculationImpl implements Calculation{  

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

}  

and finally the host configuration 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>  

following are my classes that are used

interface :-

package com.javatpoint;

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

implementation class :-

public class CalculationImpl implements Calculation{

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

}

and the main class

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

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

  2. The client port information is completely and utterly useless.

    • It isn't unique per client.
    • It isn't fixed per client.
    • It can and will change over the life of the client.

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...