java.rmi.ConnectIOException: 远程端点的非 JRMP 服务器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19831569/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 20:34:00  来源:igfitidea点击:

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

javarmi

提问by user2963824

this is a simple RMI program,howerver,it always throw exception when I run HelloClient.java .

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

create remote interface

创建远程接口

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

create remote class

创建远程类

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;
    }
}

create server:

创建服务器:

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();
        }
    }
}

create client:

创建客户端:

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();
        }
    }
}

the exception is:

例外是:

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)

The environment : jdk 1.7 +eclipse+window xp

环境:jdk 1.7 +eclipse+window xp

回答by user207421

There is something other than an RMI Registry running at port 1099 in the client host.

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

However unless the client host and the server host are the same host, you're looking up the wrong Registry anyway. You need to call getRegistry()with the server hostname, so you're looking up the Registry at the server host: the one that the server bound to.

但是,除非客户端主机和服务器主机是同一台主机,否则您查找的注册表是错误的。您需要getRegistry()使用服务器主机名进行调用,因此您正在服务器主机上查找注册表:服务器绑定到的主机。