RMI

Java RMI Projects

RMI PROJECT 1

adplus-dvertising
Display String with use of RMI
Previous Home Next

In this page of the tutorials we are going to take an Example which is describe the way to display "Hello This is the RMI Application" message using RMI.

By RMI we mean Remote Method Invocation. RMI serves as a basic technique for supporting distributed objects in java. The steps involved in displaying message Hello are described below:

Step 1: Create a Remote interface named HelloInterface.java in the Directory.

package r4r;
import java.rmi.*;
public interface HelloworldInterface extends Remote {
public String say() throws RemoteException;
}

Step 2: Create an Remote Class implementation for HelloWorld named Hello.java in the Directory.

package r4r;
import java.rmi.*;
import java.rmi.server.*;
public class hello extends UnicastRemoteObject 
implements HelloworldInterface {
private String message;
public hello (String msg) throws RemoteException {
message = msg;
}
public String say() throws RemoteException{
return message;
}
}

Step 3: Compile the above two

Step 4: After compiling the above two classes type the following command i.e-"rmic Hello" in console just like displayed below.

Your Directory Structure will be like this.By running the "rmic Hello" command a new class will be created i.e "Hello_Stub.class" in the directory

Step 5: Create Server application named HelloServer.java

package r4r;
import java.rmi.Naming;
public class HelloServer {
public static void main (String[] argv) 
{
try {
Naming.rebind 
("Hello", new hello ("Hello, This is R4RTech Soft Solution!"));
System.out.println 
("Server is connected and ready for operation.");
} 
catch (Exception e) {
System.out.println ("Server connection failure: " + e);
}
}
}

Step 6: Create Client application named HelloClient.java

package r4r;
import java.rmi.Naming;
public class HelloClient {
public static void main (String[] argv) {
try {
HelloworldInterface hello =(HelloworldInterface)
Naming.lookup ("//192.168.10.201/Hello");
System.out.println (hello.say());
} 
catch (Exception e){
System.out.println ("HelloClient exception: " + e);}
}
}

Step 7: Compile both of the files.

Step 8: Type "rmicregistry" on commandprompt and press ENTER.

Step 9: Type java HelloServer in commandprompt and press ENTER. The following message will be displayed on console.

Step 10: Now,open another separate command terminal, and run the client application like shown in the figure given below:

Step 11: If the message similar to the above appears in figure comes means that you have implemented your RMI application.

Previous Home Next