[Webinar] Streamline your web hosting managementRegister Today


Using RMI - Urgent

Posted on 2002-05-30
Medium Priority
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 1200 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:

  permission java.security.AllPermission;

  and you can use it by defining a value for the java.security.policy property:

java -Djava.security.policy=policyfilename

  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

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month10 days, 5 hours left to enroll

591 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