  | Mailing List | | Home | | Forum Home | | JBoss - Java Application Server | | Tomcat - JSP/Servlet container | | Struts - A MVC web framework | | iText - An open source PDF Java Library | | JDOM - JDOM XML Parser | | J2EE - A mailing list for Java(tm) 2 Platform, Enterprise Edition | | J2EE Pattern - An interest list for Sun Java Center J2EE Pattern Catalog | | JSP - A mailing list about Java Server Pages specification and reference | | Servlet - A mailing list for discussion about Sun Microsystem's Java Servlet API Technology | |
Struts & Hibernate
|
|
|
  | | | java.rmi.ConnectionExceptionException:Connect refused to host | java.rmi.ConnectionExceptionException:Connect refused to host 2004-11-17 - By Edward King
Back I write a rmi,when server and client runs in the same machine,it runs ok,then I run them in two machines,server runs in 192.168.0.1,like follows: C:\>rmiregistry -J-Djava.security.policy=registerit.policy C:\>java -Djava.rmi.dgc.leaseValue=1000 -Djava.security.policy=registery.policy RegisterIt Object instantiated: HelloServer[RemoteStub [ref: [endpoint:[192.168.0.1:3120](l ocal),objID:[0]]]]
and it ok ,client runs in 192.168.0.2, but it raise errors: java -Djava.security.policy=registerit.policy HelloClient HelloClient exception :java.rmi.ConnectionException:Connection refused to host :192.168.0.2;nested exception is:java.net.ConnectException :Connection refused :connect
Why? how to solve it? I have puzzled with it for many days! Please help. Any idea will be appreciated!
My code is follows: --HelloInterface.java-- public interface HelloInterface extends java.rmi.Remote{ public String sayHello() throws java.rmi.RemoteException ; }
--HelloServer.java-- import java.io.*; import java.rmi.*; import java.rmi.server.*; import java.util.*; public class HelloServer extends UnicastRemoteObject implements HelloInterface{ public HelloServer() throws RemoteException{ super(); }
public String sayHello() throws RemoteException{ return "Hello world, the current system time is "+new Date(); } }
--RegisterIt.java-- import java.rmi.*; public class RegisterIt{ public static void main(String args[]){ try{ HelloServer obj=new HelloServer(); System.out.println("Object instantiated: "+obj); Naming.rebind("/HelloServer",obj); System.out.println("HelloServer bound in registery"); } catch(Exception e){ System.out.println(e); } } }
--registerit.policy-- grant{ permission java.security.AllPermission ; };
--HelloClient.java-- import java.rmi.*; public class HelloClient{ public static void main(String args[]){ if(System.getSecurityManager()==null){ System.out.println("null"); System.setSecurityManager(new RMISecurityManager()); } try{ HelloInterface obj=(HelloInterface)Naming.lookup("/HelloServer"); String message=obj.sayHello(); System.out.println(message); } catch(Exception e){ System.out.println("HelloClient exception: "+e); } } }
=========================================================================== To unsubscribe, send email to listserv@(protected) and include in the body of the message "signoff J2EE-INTEREST". For general help, send email to listserv@(protected) and include in the body of the message "help".
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META http-equiv=Content-Type content="text/html; charset=gb2312"> <META content="MSHTML 6.00.2600.0" name=GENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=#ffffff> <DIV><FONT size=2>I write a rmi,when server and client runs in the same machine,it runs ok,then I run them in two machines,server runs in 192.168.0.1,like follows:<BR>C:\>rmiregistry -J-Djava.security.policy=registerit.policy<BR>C:\>java -Djava.rmi.dgc.leaseValue=1000 -Djava.security.policy=registery.policy RegisterIt<BR>Object instantiated: HelloServer[RemoteStub [ref: [endpoint:[192.168.0.1:3120](l<BR>ocal),objID:[0]]]]</FONT></DIV> <DIV> </DIV> <DIV><FONT size=2>and it ok ,client runs in 192.168.0.2, but it raise errors:<BR>java -Djava.security.policy=registerit.policy HelloClient<BR>HelloClient exception :java.rmi.ConnectionException:Connection refused to host:192.168.0.2;nested exception is:java.net.ConnectException :Connection refused:connect</FONT></DIV> <DIV> </DIV> <DIV><FONT size=2>Why? how to solve it? I have puzzled with it for many days! Please help.<BR>Any idea will be appreciated!</FONT></DIV> <DIV><FONT size=2> </FONT></DIV> <DIV><FONT size=2>My code is follows:<BR>--HelloInterface.java--<BR>public interface HelloInterface extends java.rmi.Remote{<BR>public String sayHello() throws java.rmi.RemoteException ;<BR>}</FONT></DIV> <DIV> </DIV> <DIV><FONT size=2>--HelloServer.java--<BR>import java.io.*;<BR>import java.rmi.*;<BR>import java.rmi.server.*;<BR>import java.util.*;<BR>public class HelloServer extends UnicastRemoteObject implements HelloInterface{<BR>public HelloServer() throws RemoteException{<BR>super();<BR>}</FONT></DIV> <DIV> </DIV> <DIV><FONT size=2>public String sayHello() throws RemoteException{<BR>return "Hello world, the current system time is "+new Date();<BR>}<BR>}</FONT></DIV> <DIV> </DIV> <DIV><FONT size=2>--RegisterIt.java--<BR>import java.rmi.*;<BR>public class RegisterIt{<BR>public static void main(String args[]){<BR>try{<BR>HelloServer obj=new HelloServer();<BR>System.out.println("Object instantiated: "+obj);<BR>Naming.rebind("/HelloServer",obj);<BR>System.out.println("HelloServer bound in registery");<BR>}<BR>catch(Exception e){<BR>System.out.println(e);<BR>} <BR>}<BR>}</FONT></DIV> <DIV> </DIV> <DIV><FONT size=2>--registerit.policy--<BR>grant{<BR>permission java.security.AllPermission ;<BR>}; </FONT></DIV> <DIV> </DIV> <DIV><FONT size=2>--HelloClient.java--<BR>import java.rmi.*;<BR>public class HelloClient{<BR>public static void main(String args[]){<BR>if(System.getSecurityManager()==null){<BR>System.out.println("null" );<BR>System.setSecurityManager(new RMISecurityManager());<BR>}<BR>try{<BR>HelloInterface obj=(HelloInterface)Naming.lookup("/HelloServer");<BR>String message=obj.sayHello();<BR>System.out.println(message);<BR>}<BR>catch(Exception e){<BR>System.out.println("HelloClient exception: "+e);<BR>}<BR>}<BR>}<BR></FONT></DIV></BODY></HTML> =========================================================================== To unsubscribe, send email to listserv@(protected) and include in the body of the message "signoff J2EE-INTEREST". For general help, send email to listserv@(protected) and include in the body of the message "help". <p>
|
|
 |