Improve company productivity with a Business Account.Sign Up

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 274
  • Last Modified:

Using RMI - Urgent

Just been arse-raped by a lecturer, and now have two assignments due on monday where previously only one of them was.

One of these assignments involves a partial (yet functional) re-write of a program we write using sockets, into RMI.

Basically, I'm after every bit of info on getting an RMI program to work that you can possibly throw at me. I have no shortage of question points and will happily give away a lot of them for rapid responses to this.

I am just about to go finish coding my sockets implementation. After that I'm going to bed. Ideally, I'd like to get up in the morning with enough information sitting in this thread that I can sit down tomorrow and code the RMI up, without wasting half the day figuring out how to make it work.

Main points of interest: security. I know I need a txt file of some sort with the security policy. Security isn't a big deal, but I do need a policy of some sort for it to work at all. How do I go about setting up this? Basically I just want to make ports 5100 to 5105 open and accessible to all and sundry (this will all be running behind a phat uni firewall, and for no longer than 5 minutes at a time, so there's little risk). I doubt I'll need more than one open, but having 6 there gives me some maneuverability without needing to be editing it later. How do I set this file up? How do I make the RMI program recognise it as a security policy and adhere to it? RMI wasn't covered in much detail in the lectures. The sample assignment code doesn't contain a policy file (and thus doesn't work), and at the time we covered it (oh so briefly) in classes, there were other assignments to be thinking about.

My other main point of interest: something about stub files. What are these? Apparently I need to use rmic to compile an RMI program (or just to create the stub files? I know not). Assuming I have fully functionaly, syntactically, and logically correct code, how do I go about compiling it so it will run, connect, and operate? I am writing both client and server software (very simplistic implementations thereof though; 5 hours coding tops once I know how to make it compile and run properly).

Any other information/tips/anecdotes/whatever you can provide to someone who has a basic understanding of the principles of RMI coding but no actual experience doing it would be much appreciated and well rewarded.

300 points for now, to attract attention. Expect more.
  • 2
1 Solution
tutorial on how to build the simplest HelloWorld RMI app
 Basically RMI is Java's implementation for remote procedure calls for Java-to-Java distributed object communication. A Java object can register itself as being remotely accessible, bind it to an RMI registry and a client can look-up for this object, receive a reference to this object and access it as if it were local.

  Since the client and the server object can reside on different machines a mechanism for communication between client and server is needed. The first step to this is to define the remote interface (that describes the methods with which the client can use to interact with the server object through RMI). Once the remote interface is defined you simply write the implementation class and use the rmiregistry (it is included with the J2SDK) to register the object.

  Both server and client classes must first be compiled with the javac. After this the remote implementation class must be compiled using the rmic (it comes with the J2SDK as well) to produce the stub class. The stub class allows the client to invoke the server object's remote methods. The stub receives each remote call and passes it to the Java RMI systems that performs the networking that allows the client to connect to the server and interact with the remote server object.

  To compile the server class you simply need to do: rmic -v1.2 <classfilename>

  The -v1.2 indicates that the classes will be used by the J2SE vm and not by any earlier. The reason we need it, is because in the pro-java 2 systems two classes were needed in order for the RMI to run; the stub and the skeleton. Once you are done start the rmiregistry by simply typing; rmiregistry. That's more or less it. You have the server up and running.

  With regards to security issues you might want to restrict the acitons performed by remotely loaded classes. This can be done by installing a security manager because by default an RMI programme does not have a security manager (and therefore there are no restrictions placed on rempotely loaded loaded objects). The java.rmi provides a default manager security implementation that you can install using:

if(System.getSecurityManager() == null)
     System.setSecurityManager(new RMISecurityManager());

 If you would like to use your own security manager implementation you will need to specify (in Java 2) a security policy file at run-time. A sample policy file that grants full access permissions to everyone will look like:


  and you can use it by defining a value for the property:


  For more information/tutorials on rmi take a look here:

  and on rmi security/permissions

  Hope it helps.
SubhumanAuthor Commented:
Thanks very much. I was expecting more responses but yours sufficed, so it's all good.
 Thank you for the points. I am glad I helped :-)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now