Search code examples
javarmi

NoSuchObjectException - No such object in table


I'm try to set up a simple RMI implementation, but I'm having some trouble.

The server starts up fine, but the client can never seem to find the remote object (Naming.lookup fails every time). From reading around people have mentioned storing the remote object (Bank) in a static variable, but that hasn't worked either.

UPDATE: If I remove all references to the port number, the whole thing seems to work fine. Does anyone know why that is?

Server:

public class Bank extends UnicastRemoteObject implements BankInterface {

    public static void main(String args[]) throws Exception {

        try{
            System.setSecurityManager(new SecurityManager());
            System.out.println("Security Manager set.");

            Bank myBank = new Bank(Integer.parseInt(args[0]));
            System.out.println("Bank instance created");

            Naming.rebind("Bank", myBank);
            System.out.println("Name rebind completed.");
            System.out.println("Server ready for requests!");

        }catch(Exception e){
            System.out.println("Error in main - " + e.toString());
        }
    }
}

Client

public class ATM {

    public static void main (String args[]) throws Exception {
        String URL = "//" + args[0] + ":" + args[1] + "/Bank";
        System.out.println("Connecting to: " + URL);
        BankInterface bank = (BankInterface)Naming.lookup(URL);
        System.out.println("Connected!");
    }
}

Stacktrace

Exception in thread "main" java.rmi.NoSuchObjectException: no such object in tab
le
        at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Stream
RemoteCall.java:276)
        at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:
253)
        at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:379)
        at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
        at java.rmi.Naming.lookup(Naming.java:101)
        at ATM.main(ATM.java:8)

Commands I'm running from cmd.exe are:

rmiregistry

java Bank 7777

java ATM localhost 7777 testMethod


Solution

  • You're running the Registry on its default port, and binding to that Registry, by not using a port number in the bind string, but you're looking up a non-existent Registry on port 7777. The bind string and the lookup string should be the same.

    NB lookup isn't the same as connecting. There is no connection to your remote object until you call one of its remote methods.