i was trying to run a program on RMI
i did the following

import java.rmi.*; 
public interface HelloInterface extends Remote {
    public int  add() throws RemoteException;
}
import java.rmi.*;
import java.rmi.server.*;

public class Hello extends UnicastRemoteObject implements HelloInterface {
  private int m,n,message, k,l;
  public Hello (int m,int n) throws RemoteException {
     k=m;
     l=n;
	 message=k+1;
  }
  public int  add() throws RemoteException {
    return message;
  }
}

after compiling these two i typed "rmic Hello"
and then this

import java.rmi.Naming;

public class HelloServer 
{
  public static void main (String[] argv) 
  {
    try {
      Naming.rebind ("Hello", new Hello (4,5));
      System.out.println ("Server is connected and ready for operation.");
    } 
  catch (Exception e) {
      System.out.println ("Server not connected: " + e);
    }
  }
}
import java.rmi.Naming;

public class HelloClient 
{
    public static void main (String[] argv) {
    try {
      HelloInterface hello =(HelloInterface) Naming.lookup ("//192.168.10.201/Hello");
      System.out.println (hello.add());
    } 
  catch (Exception e){
    System.out.println ("HelloClient exception: " + e);}
  }
}

after compiling these two.... Type "rmicregistry" on commandprompt and press ENTER....this is not working..dos does not understand the command..help

I have made a slight change in file called "HelloClient.java"
and i get the program run succesfully

replace the above file with the following code:

import java.rmi.Naming;

public class HelloClient
{
public static void main (String[] argv) {
try {
HelloInterface hello =(HelloInterface) Naming.lookup ("Hello");
System.out.println (hello.add());
}
catch (Exception e){
System.out.println ("HelloClient exception: " + e);}
}
}

Execute files in the following way:

1.compile all the files ("HelloInterface.java","Hello.java","HelloServer.java","HelloClient.java")

2.start rmiregistry

3.java HelloServer

4.open another command prompt

5.java HelloClient

After the above 5 steps u will get the output as '5'


gud time

mahkris

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.