0% found this document useful (0 votes)
24 views3 pages

Rmi in Java

This document discusses RMI (Remote Method Invocation) in Java. It defines an interface called Inter with a method getMessage that returns an int. It then implements this interface in a class called InterImpl with a main method that registers the object with RMI. Finally, it shows a client class that looks up the remote object and calls getMessage, printing the result.

Uploaded by

Manu Prasad
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views3 pages

Rmi in Java

This document discusses RMI (Remote Method Invocation) in Java. It defines an interface called Inter with a method getMessage that returns an int. It then implements this interface in a class called InterImpl with a main method that registers the object with RMI. Finally, it shows a client class that looks up the remote object and calls getMessage, printing the result.

Uploaded by

Manu Prasad
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

RMI IN JAVA

InterImpl.java

import java.rmi.*;
import java.rmi.server.*;
import java.util.*;

public class InterImpl extends UnicastRemoteObject implements Inter


{
String s1[]={"How are you","I am Fine","What about you"};
public InterImpl() throws RemoteException
{
}
public int getMessage(int c) throws RemoteException
{
int i,s;
s=1;
for(i=1;i<=c;i++)
{
s=s*i;
}
return s;
}
public static void main(String args[])
{
try
{
InterImpl x= new InterImpl();
Naming.rebind("rmi://localhost:1099/ABC",x);
System.out.println("Server Registered");
}
catch(Exception e)
{
e.printStackTrace();
}
}
}

Inter.java

import java.rmi.*;
import java.rmi.server.*;

interface Inter extends Remote


{
int getMessage (int a) throws RemoteException;
}
Clientrmi.java

import java.rmi.*;
public class Clientrmi
{
public static void main(String args[])
{
try
{
int a= Integer.parseInt(args[0]);
Inter
i=(Inter)Naming.lookup("rmi://localhost:1099/ABC");
System.out.println("Factorial of "+a+" := "
+i.getMessage(a));
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
OUTPUT:

You might also like