java.rmi.ConnectIOException : non-JRMP server at remote endpoint

标签 java rmi

这是一个简单的RMI程序,但是,当我运行HelloClient.java时,它总是抛出异常。

创建远程接口(interface)

public interface Hello extends Remote {
    String sayHello(String name) throws RemoteException;
}

创建远程类

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
public class HelloImpl extends UnicastRemoteObject implements Hello {

    protected HelloImpl() throws RemoteException {
        super();
    }

    @Override
    public String sayHello(String name) throws RemoteException {
        System.out.println("HelloImpl:" + name);
        return name;
    }
}

创建服务器:

import java.rmi.RMISecurityManager;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

public class HelloServer {
    public static final int port = 1099;

    public static void main(String[] args) {
        try {
            if (System.getSecurityManager() == null) {
                System.setSecurityManager(new RMISecurityManager());
            }
            Registry registry = LocateRegistry.createRegistry(port);
            HelloImpl impl = new HelloImpl();
            registry.rebind("//SEJ1T1DYN68BZBF:1099/HelloService", impl);
            String[] names = registry.list();
            for (String name : names) {
                System.out.println(name);
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

创建客户端:

import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

public class HelloClient {

    public static void main(String[] args) {
        try {
            Registry registry = LocateRegistry.getRegistry();
            Hello hello = (Hello) registry
                    .lookup("//SEJ1T1DYN68BZBF:1099/HelloService");
            System.out.println(hello.sayHello("javamaj blog"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

异常(exception)情况是:

java.rmi.ConnectIOException: non-JRMP server at remote endpoint
    at sun.rmi.transport.tcp.TCPChannel.createConnection(Unknown Source)
    at sun.rmi.transport.tcp.TCPChannel.newConnection(Unknown Source)
    at sun.rmi.server.UnicastRef.newCall(Unknown Source)
    at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
    at HelloClient.main(HelloClient.java:10)

环境: jdk 1.7 +eclipse+window xp

最佳答案

除了 RMI 注册表之外,还有其他东西在客户端主机的端口 1099 上运行。

但是,除非客户端主机和服务器主机是同一主机,否则您无论如何都会查找错误的注册表。您需要使用服务器主机名调用 getRegistry(),这样您就可以在服务器主机上查找注册表:服务器绑定(bind)到的主机。

关于java.rmi.ConnectIOException : non-JRMP server at remote endpoint,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19831569/

相关文章:

java - 在手动单击页面之前,无法识别页面上的元素

java - Tomcat 身份验证和特定 Web 应用程序身份验证

java - 如何在 RMI 方法的参数中传递对象?

java rmi - 访问被拒绝 ("java.net.SocketPermission" "127.0.0.1:1099" "connect,resolve")

java - Spring Hibernate 未将实体映射到 PostGres 中的现有表

java - 是否可以直接将 Button 添加到 ScrolledComposite 中?

java - 如何隔离特定于平台的 JNA 绑定(bind)?

java - 使用端口 1099 的 IntelliJ Idea IDE

java - 当通过 RMI 在 Java5 和 Java6 之间进行通信时,我是否应该预料到会出现问题?

java - 运行 RMI 服务器时出现问题