  | 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 Kurien Joseph
Back * First check if you can ping both machines from each other. * If you still can ping make sure the localhost setting in your host file to map to the IP address instead of the 127.0.0.1 loopback.
-Kurien
__ __
From: A mailing list for Java(tm) 2 Platform, Enterprise Edition [mailto:J2EE-INTEREST@(protected)] On Behalf Of Edward King Sent: Wednesday, November 17, 2004 12:41 AM To: J2EE-INTEREST@(protected) Subject: java.rmi.ConnectionExceptionException:Connect refused to host
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".
=========================================================================== 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".
<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft -com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns="http: //www.w3.org/TR/REC-html40">
<head> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii"> <meta name=Generator content="Microsoft Word 11 (filtered medium)"> <!--[if !mso]> <style> v\:* {behavior:url(#default#VML);} o\:* {behavior:url(#default#VML);} w\:* {behavior:url(#default#VML);} .shape {behavior:url(#default#VML);} </style> <![endif]--> <style> <!-- /* Font Definitions */ @(protected) {font-family:Wingdings; panose-1 (See http://ose-1.ora-code.com):5 0 0 0 0 0 0 0 0 0;} @(protected) {font-family:SimSun; panose-1 (See http://ose-1.ora-code.com):2 1 6 0 3 1 1 1 1 1;} @(protected) {font-family:Tahoma; panose-1 (See http://ose-1.ora-code.com):2 11 6 4 3 5 4 4 2 4;} @(protected) {font-family:"\@(protected)"; panose-1 (See http://ose-1.ora-code.com):0 0 0 0 0 0 0 0 0 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {margin:0in; margin-bottom:.0001pt; font-size:12.0pt; font-family:SimSun;} a:link, span.MsoHyperlink {color:blue; text-decoration:underline;} a:visited, span.MsoHyperlinkFollowed {color:purple; text-decoration:underline;} span.EmailStyle17 {mso-style-type:personal-reply; font-family:Arial; color:navy;} @(protected) Section1 {size:8.5in 11.0in; margin:1.0in 1.25in 1.0in 1.25in;} div.Section1 {page:Section1;} /* List Definitions */ @(protected) l0 {mso-list-id:1796213936; mso-list-type:hybrid; mso-list-template-ids:608627832 1109938394 67698691 67698693 67698689 67698691 67698693 67698689 67698691 67698693;} @(protected) l0:level1 {mso-level-start-at:2; mso-level-number-format:bullet; mso-level-text:\F0B7; mso-level-tab-stop:.5in; mso-level-number-position:left; text-indent:-.25in; font-family:Symbol; mso-fareast-font-family:SimSun; mso-bidi-font-family:Arial;} ol {margin-bottom:0in;} ul {margin-bottom:0in;} --> </style> <!--[if gte mso 9]><xml> <o:shapedefaults v:ext="edit" spidmax="1026" /> </xml><![endif]--><!--[if gte mso 9]><xml> <o:shapelayout v:ext="edit"> <o:idmap v:ext="edit" data="1" /> </o:shapelayout></xml><![endif]--> </head>
<body bgcolor=white lang=EN-US link=blue vlink=purple>
<div class=Section1>
<ul style='margin-top:0in' type=disc> <li class=MsoNormal style='color:navy;mso-list:l0 level1 lfo1'><font size=2 color=navy face=Arial><span style='font-size:10.0pt;font-family:Arial' >First check if you can ping both machines from each other.<o:p></o:p></span>< /font></li> <li class=MsoNormal style='color:navy;mso-list:l0 level1 lfo1'><font size=2 color=navy face=Arial><span style='font-size:10.0pt;font-family:Arial'>If you still can ping make sure the localhost setting in your host file to map to the IP address instead of the 127.0.0.1 loopback.<o:p></o:p></span> </font></li> </ul>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size: 10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size: 10.0pt;font-family:Arial;color:navy'>-Kurien<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size: 10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size: 10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>
<div>
<div class=MsoNormal align=center style='text-align:center'><font size=3 face=SimSun><span style='font-size:12.0pt'>
<hr size=2 width="100%" align=center tabindex=-1>
</span></font></div>
<p class=MsoNormal><b><font size=2 face=Tahoma><span style='font-size:10.0pt; font-family:Tahoma;font-weight:bold'>From:</span></font></b><font size=2 face=Tahoma><span style='font-size:10.0pt;font-family:Tahoma'> A mailing list for Java(tm) 2 Platform, Enterprise Edition [mailto:J2EE-INTEREST@(protected)] <b><span style='font-weight:bold'>On Behalf Of </span></b>Edward King<br> <b><span style='font-weight:bold'>Sent:</span></b> Wednesday, November 17, 2004 12:41 AM<br> <b><span style='font-weight:bold'>To:</span></b> J2EE-INTEREST@(protected)<br> <b><span style='font-weight:bold'>Subject:</span></b> java.rmi.ConnectionExceptionException:Connect refused to host</span></font><o:p ></o:p></p>
</div>
<p class=MsoNormal><font size=3 face=SimSun><span style='font-size:12.0pt'><o:p > </o:p></span></font></p>
<div>
<p class=MsoNormal><font size=2 face=SimSun><span style='font-size:10.0pt'>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]]]]</span></font><o:p></o:p></p>
</div>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size: 12.0pt;font-family:"Times New Roman"'> </span></font><o:p></o:p></p>
</div>
<div>
<p class=MsoNormal><font size=2 face=SimSun><span style='font-size:10.0pt'>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</span></font><o:p></o:p></p>
</div>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size: 12.0pt;font-family:"Times New Roman"'> </span></font><o:p></o:p></p>
</div>
<div>
<p class=MsoNormal><font size=2 face=SimSun><span style='font-size:10.0pt'>Why? how to solve it? I have puzzled with it for many days! Please help.<br> Any idea will be appreciated!</span></font><o:p></o:p></p>
</div>
<div>
<p class=MsoNormal><font size=2 face="Times New Roman"><span style='font-size: 10.0pt;font-family:"Times New Roman"'> </span></font><o:p></o:p></p>
</div>
<div>
<p class=MsoNormal><font size=2 face=SimSun><span style='font-size:10.0pt'>My code is follows:<br> --HelloInterface.java--<br> public interface HelloInterface extends java.rmi.Remote{<br> public String sayHello() throws java.rmi.RemoteException ;<br> }</span></font><o:p></o:p></p>
</div>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size: 12.0pt;font-family:"Times New Roman"'> </span></font><o:p></o:p></p>
</div>
<div>
<p class=MsoNormal><font size=2 face=SimSun><span style='font-size:10.0pt'>- -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> }</span></font><o:p></o:p></p>
</div>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size: 12.0pt;font-family:"Times New Roman"'> </span></font><o:p></o:p></p>
</div>
<div>
<p class=MsoNormal><font size=2 face=SimSun><span style='font-size:10.0pt' >public String sayHello() throws RemoteException{<br> return "Hello world, the current system time is "+new Date();<br> }<br> }</span></font><o:p></o:p></p>
</div>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size: 12.0pt;font-family:"Times New Roman"'> </span></font><o:p></o:p></p>
</div>
<div>
<p class=MsoNormal><font size=2 face=SimSun><span style='font-size:10.0pt'>- -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> }</span></font><o:p></o:p></p>
</div>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size: 12.0pt;font-family:"Times New Roman"'> </span></font><o:p></o:p></p>
</div>
<div>
<p class=MsoNormal><font size=2 face=SimSun><span style='font-size:10.0pt'>- -registerit.policy--<br> grant{<br> permission java.security.AllPermission ;<br> }; </span></font><o:p></o:p></p>
</div>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size: 12.0pt;font-family:"Times New Roman"'> </span></font><o:p></o:p></p>
</div>
<div>
<p class=MsoNormal><font size=2 face=SimSun><span style='font-size:10.0pt'>- -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> }</span></font><o:p></o:p></p>
</div>
</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> =========================================================================== 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>
|
|
 |