java - RMI server to judge the host name of client which called it -


i have below program of spring rmi in client send port no s received @ server end , being displayed , using spring rmi achieve want there way since want remove hard coding client notsent hostname client call servre rmi server , rmi server should smart enough judge client host name , please advise f in below program stop passing hostname client side how server smart enough judge client hostname

calculation interface there should method takes string parameter.

public interface calculation {   void print(string text );   void registeripaddress(string ip); }   public class calculationimpl implements calculation {  @override void print(string text) {     system.out.println(text); }     @override     void registeripaddress(string ip){             list.add(ip);//or whatever want } 

your xml files both client , host right applicationcontext.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> 

client-beans.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="org.springframework.remoting.rmi.rmiproxyfactorybean"> <property name="serviceurl" value="rmi://localhost:1099/calculationservice"></property> <property name="serviceinterface" value="com.javatpoint.calculation"></property> </bean> </beans> 

create new instance of applicaioncontext in order work

class server {     public static void main(string[] args) {         applicationcontext context = new classpathxmlapplicationcontext("applicationcontext.xml");     } } 

need run client

public static void main(string[] args) {     applicationcontext context = new classpathxmlapplicationcontext("client-beans.xml");     calculation calculation = (calculation) context.getbean("calculationbean");     calculation.print("copied&pasted!");      try {         calculation.registeripaddress(inetaddress.getlocalhost().gethostaddress());     } catch (unknownhostexception e) {         // todo auto-generated catch block         e.printstacktrace();     } } 

upon googling can see method

public static string getclienthost()                             throws servernotactiveexception 

now need extend remote server class can't achieve same thing in spring rmi itself


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -