RMI客户端与另一个端口

时间:2014-01-10 10:44:06

标签: client-server port rmi

我真的经常搜索数小时但我找不到任何解决方案。我希望VM上的客户端(Windows服务器2008)与我的主机(主系统:Windows 7)进行通信。

public class TestClient
{
    public static void main(String[] args) throws RemoteException, NotBoundException
    {
        Registry registry = LocateRegistry.getRegistry("13.211.124.80",TestRemote.RMI_PORT);
        TestRemote remote = (TestRemote) registry.lookup(TestRemote.RMI_ID);
        System.out.println(remote.isLoginValid("tst"));
        System.out.println(remote.isLoginValid("test"));
        System.out.println(TestRemote.RMI_PORT);
    }
}

来自主持人的IP:13.211.124.80

RMI服务器类

public class RMIServer
{
    public static void main (String[] args) throws RemoteException, AlreadyBoundException
    {
        RemoteImpl impl = new RemoteImpl();
        Registry registry=LocateRegistry.createRegistry(TestRemote.RMI_PORT);
        registry.bind(TestRemote.RMI_ID, impl);
        System.out.println("server is started");
    }
}

Impl Class:

public class RemoteImpl extends UnicastRemoteObject implements TestRemote
{
    private static final long serialVersionUID = 1L;    
    protected RemoteImpl() throws RemoteException
    {
        super();
        // TODO Auto-generated constructor stub 
    }

    public boolean isLoginValid(String username) throws RemoteException
    {
        if (username.equals("test"))
        {
            return true;
        }
        return false;
    }
}

接口类:

public interface TestRemote extends Remote
{
    public boolean isLoginValid(String username) throws RemoteException;
    public static final String RMI_ID = "TestRMI";
    public static final int RMI_PORT = 888;
}

错误:

  

线程“main”中的异常java.rmi.UnmarshalException:错误解组返回;嵌套异常是:       java.lang.ClassNotFoundException:com.interf.test.TestRemote(没有安全管理器:禁用RMI类加载器)

1 个答案:

答案 0 :(得分:0)

异常非常清楚。无论什么组件抛出该异常,它的CLASSPATH上都没有该类。它可能是注册表或客户端,具体取决于堆栈跟踪,您没有完全发布。