简体   繁体   English

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

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

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

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() ,因此您需要在服务器主机上查找注册表:服务器绑定到的注册表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM