Using RMI - Urgent

Posted on 2002-05-30
Last Modified: 2013-12-29
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.
Question by:Subhuman
  • 2
LVL 16

Expert Comment

ID: 7044775
tutorial on how to build the simplest HelloWorld RMI app
LVL 35

Accepted Solution

girionis earned 300 total points
ID: 7045232
 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.

Author Comment

ID: 7046577
Thanks very much. I was expecting more responses but yours sufficed, so it's all good.
LVL 35

Expert Comment

ID: 7046595
 Thank you for the points. I am glad I helped :-)

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
map related example 6 55
difference of if loops 23 62
throw exception 21 58
ejb stateless example 2 25
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question