【问题标题】:how to solve java.rmi.ConnectException in java program?如何解决java程序中的java.rmi.ConnectException?
【发布时间】: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 端口上。

标签: java sockets rmi


【解决方案1】:

命名类提供了在远程对象注册表中存储和获取对远程对象的引用的方法。 Naming 类的每个方法都将一个名称作为其参数之一,该名称是一个 java.lang.String,采用 URL 格式(不包括方案组件),形式如下:

//host:port/name

以 URL 格式添加名称

//10.7.150.18:9999/Server

【讨论】:

  • :我们在代理环境中使用RMI,这会导致什么问题吗?
  • 在代理环境中?完全无法理解这一点。您的服务器和客户端是否可以相互访问?还是您的意思是说您使用某些代理服务器访问您的服务器?
  • @实际上,我们的校园通过代理设置完全限制了互联网访问。所以,现在我使用的客户端和服务器机器在同一个校园里。服务器机器和客户端机器都在代理设置下工作。什么我现在做?
  • 所以要访问互联网,您需要使用一些代理服务器,但对于访问服务器和客户端,您不使用任何代理...无论如何,即使有防火墙或任何代理,请参考以下链接docs.oracle.com/javase/6/docs/technotes/guides/rmi/…
  • 这里没有什么可以回答这个问题。 -1.
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-02-25
  • 2022-12-05
  • 2022-01-10
相关资源
最近更新 更多