Sei sulla pagina 1di 7

SERVER PROGRAM:

import java.io.*;
import java.rmi.*;
import javax.swing.table.*;
import java.rmi.server.*;
import java.rmi.registry.*;
interface inter extends Remote{
public int add(int one , int two) throws RemoteException;
public int sub(int one , int two) throws RemoteException;
}
public class servers extends UnicastRemoteObject implements inter{
public servers() throws RemoteException
{}
public int add(int one , int two) throws RemoteException{
System.out.println("came in "+one+" "+two);
return (one+two);
}
public int sub(int one , int two) throws RemoteException{
System.out.println("came in "+one+" "+two);
return (one-two);
}
public static void main(String args[]) throws Exception
{
try
{ server s = new servers();
System.out.println("created");
LocateRegistry.createRegistry(1099);
Naming.rebind("sample",s);
}catch(RemoteException e)
{System.out.println("error "+e);
}}}

CLIENT PROGRAM:
import java.io.*;
import java.rmi.*;
import java.rmi.server.*;
import java.rmi.registry.*;
import java.lang.*;
import java.util.Scanner;
interface inter extends Remote{
public int add(int one , int two) throws RemoteException;
public int sub(int one , int two) throws RemoteException;
}
public class clients extends UnicastRemoteObject {
public clients() throws RemoteException
{}
public static void main(String args[])
{
inter in = null;
int value;
Scanner i = new Scanner(System.in);
System.out.println("Enter your balance");
value = i.nextInt();
System.out.println("You balance is "+value);
int wd,dep,ch=1;
System.out.println("banking system");
System.out.println("1.Deposit of cash");
System.out.println("2.withdrawal of cash");
System.out.println("3.exit");
System.out.println("Choose");
while(ch!=3)
{
System.out.println("Enter your choice");
ch = i.nextInt();
System.out.println("You choice is "+ch);
try{
if(ch==1){
System.out.println("Enter the amount to deposit");
dep = i.nextInt();
in = (inter) Naming.lookup("rmi://"+"192.168.54.22"+":1099/sample");
value = in.add(value,dep);
System.out.println(" your balance : "+value);}
if(ch==2){
if(value<1000){
System.out.println("your balance is low you can't withdraw amount");}
else{
System.out.println("Enter the amount to withdraw")in = (inter)
Naming.lookup("rmi://"+"192.168.54.22"+":1099/sample");
wd = i.nextInt();
value = in.sub(value,wd);
System.out.println(" your balance : "+value);}}
if(ch>3)
{System.out.println("Enter a valid choice");}
}catch(Exception ev){
System.out.println("error "+ev);
}} }}
OUTPUT:
SERVER:

CLIENT:
RESULT:
Thus the bank transaction has been implemented using java
remote method invocation and output has been verified.

Potrebbero piacerti anche