user2963824
user2963824

Reputation: 21

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 .

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

Upvotes: 2

Views: 31344

Answers (1)

user207421
user207421

Reputation: 310903

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

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.

Upvotes: 1

Related Questions