Aim: -
Write a RMI Program to Simple hello messages.
Tools: -
NetBeans IDE, jdk
Program:-
Interface:-
import
java.rmi.Remote;
public
interface calculator extends Remote {
public String Printmsg() throws
java.rmi.RemoteException;
}
Server:-
import
java.rmi.RemoteException;
import
java.rmi.registry.LocateRegistry;
import
java.rmi.server.UnicastRemoteObject;
import
java.rmi.registry.Registry;
public
class Rmicalc implements calculator{
String message;
public Rmicalc(String msg){
message=msg; }
public String Printmsg() throws
java.rmi.RemoteException{
return message; }
public
static void main(String[] args) throws RemoteException {
Rmicalc rm=new Rmicalc("demo print
msg");
calculator stub=(calculator)
UnicastRemoteObject.exportObject(rm,0);
Registry
reg=LocateRegistry.getRegistry();
reg.rebind("demo", stub);
System.out.println("server is
ready"); }
}
Client:-
import
java.lang.invoke.MethodHandles;
import
java.rmi.NotBoundException;
import
java.rmi.Remote;
import
java.rmi.RemoteException;
import
java.rmi.registry.LocateRegistry;
import
java.rmi.registry.Registry;
public
class client {
public static void main(String s[]) throws
RemoteException, NotBoundException{
Registry
reg=LocateRegistry.getRegistry("localhost");
calculator skelton=(calculator)reg.lookup("demo");
System.out.println();
System.out.println("Message is
: " + skelton.Printmsg());
}
Output:-
0 Comments