Aim: -
Write an RMI Program to Fibonacci series summation.
Tools: -
NetBeans IDE, jdk
Program:-
Interface:-
import java.rmi.Remote;
public interface demointfs extends
Remote {
public int[] prntmsg(int x) throws Exception;
}
Server:-
import java.rmi.registry.LocateRegistry;
import
java.rmi.server.UnicastRemoteObject;
import java.io.*;
import java.sql.*;
import java.net.*;
import java.io.DataOutputStream;
import java.io.PrintStream;
public class demoserver implements
demointfs{
private String message;
String s;
public int[] prntmsg(int x) throws Exception{
int a=0,b=1,res=0,i=0,j=2;
int
ary[]=new int[x];
ary[i]=a;
i++;
ary[i]=b;
i++;
while(j<x){
res=a+b;
a=b;
b=res;
ary[i]=res;
i++;
j++;
}
return
ary;
}
public static void main(String[] args) throws Exception {
demoserver h=new demoserver();
demointfs stub=(demointfs)UnicastRemoteObject.exportObject(h,0);
java.rmi.registry.Registry registry= LocateRegistry.getRegistry();
registry.rebind("hello", stub);
System.out.println("Server is ready");
}
}
Client:-
import
java.rmi.NotBoundException;
import
java.rmi.registry.LocateRegistry;
import
java.rmi.registry.Registry;
import
java.io.IOException;
import
java.io.BufferedReader;
import
java.io.InputStreamReader;
public class
client {
public static void main(String args[])
throws Exception{
int i;
BufferedReader
br=new BufferedReader(new InputStreamReader(System.in));
System.out.println();
System.out.print("Enter Number : ");
String
str=br.readLine();
int nm=Integer.parseInt(str);
Registry
reg=LocateRegistry.getRegistry("localhost");
System.out.println("Fibonacci Series : ");
demointfs
h=(demointfs)reg.lookup("hello");
int a[]=h.prntmsg(nm);
for(i=0;i<a.length;i++)
{
System.out.println(a[i]);
}
}
}
0 Comments