-1

I'm currently playing with remote environments using rmi registry. My server is like this:

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


public class Server {
    public static void main(String args[]){
        if(args.length");
            System.exit(-1);
        }     
        try{
            Registry r=LocateRegistry.getRegistry();
        MethodsImp methods=new MethodsImp();
            //have the object to be remotely accessed so will bind it to the registry
            System.out.println("Will register on "+args[0]);
           r.rebind(args[0], methods);
        }
        catch(Exception e){
            System.out.println("Something went wrong when registring the methods");
            System.out.println(e.getMessage());
            System.exit(-1);
        }

    }

}

When I run the program by:

java -classpath /home/outsider/Desktop/RIM/RIM_TP1_correct/src -Djava.rmi.server.codebase=file:/home/outsider/Desktop/RIM/RIM_TP1_correct/src/ Server regsiter_name

I get this:

Will register on regsiter_name
Something went wrong when registring the methods
null

For some reason when I used r.rebind it throws an exception which has the message null. Before trying to run the program I install the rmiregistry by doing

rmiregistry &

On the shell. I can't find out what I'm doing wrong. If anyone could help it would be great

out_sider
  • 1
  • 2

1 Answers1

0

The problem with your code is you need to export your remote object

MethodsImp methods=new MethodsImp();

to the rmi registry.

you can do it by including this code

MethodsImp methods=new MethodsImp();
Hello stub = (Hello) UnicastRemoteObject.exportObject(methods, 0);

Hello is the name of the interface.

This code exports your object to the registry. Its not needed to export your object if you are implementing the interface and binding the object both in the same class.In case you use a different class to bind the object you need to export the object as well.

rgksugan
  • 3,342
  • 11
  • 42
  • 53
  • You don't know that. Most remote objects extend `UnicastRemoteObject` and don't need to be explicitly exported. You can't possibly know what the problem is without a stack trace. – user207421 May 22 '16 at 03:58
  • And there no such thing as 'export to the RMI Registry'. There is exporting, period, and there is *binding* to the Registry. – user207421 Mar 17 '17 at 23:35