【发布时间】:2012-06-16 05:45:31
【问题描述】:
我创建了一个简单的 java RMI 程序来了解它是如何工作的。但是当我尝试运行我的服务器端时,它会引发以下异常。
编辑:我们正在使用代理连接...
Remote exception: java.rmi.ConnectException: Connection refused to host: 10.7.150.18; nested exception is:
java.net.ConnectException: Connection refused: connect
这是我的服务器端代码供您参考...
import java.rmi.*;
import java.rmi.server.*;
import java.rmi.registry.*;
public class SampleServerImpl extends UnicastRemoteObject implements SampleServer
{
SampleServerImpl() throws RemoteException
{
super();
}
@Override
public int sum(int a,int b) throws RemoteException
{
return a + b;
}
public static void main(String[] args)
{
try
{
//set the security manager
//System.setSecurityManager(new RMISecurityManager());
//create a local instance of the object
SampleServerImpl Server = new SampleServerImpl();
//put the local instance in the registry
Naming.rebind("//10.7.150.18:9999" , Server);
System.out.println("Server waiting.....");
}
catch (java.net.MalformedURLException me)
{
System.out.println("Malformed URL: " + me.toString());
}
catch (RemoteException re)
{
System.out.println("Remote exception: " + re.toString());
}
}
}
请指导我摆脱这个问题...
【问题讨论】:
-
提供的信息不足。绑定的时候收到了吗?抬头的时候?还是在执行远程方法时?
-
@EJP : 当使用 java.exe 运行这个文件时
-
这实际上并没有回答我的问题,答案就在您应该发布的堆栈跟踪中,但如果您的意思是绑定时发生,则意味着 RMI 注册表没有运行在该主机的 9999 端口上。