Remote Method Invocation - Atm: Smvec
Remote Method Invocation - Atm: Smvec
:
REMOTE METHOD INVOCATION - ATM
INTERFACE :
import java.rmi.*;
import java.rmi.server.*;
public interface CalcInterface extends Remote
{
public int withdraw(int b)throws RemoteException;
public int dep(int d)throws RemoteException;
}
IMPLEMENTATION :
import java.rmi.*;
import java.rmi.server.*;
public class CalcImpl extends UnicastRemoteObject implements CalcInterface
{
public CalcImpl() throws RemoteException
{
}
int a=10000;
public int withdraw(int c) throws RemoteException
{
a= a-c;
return a;
}
public int dep(int e) throws RemoteException
{
a=a+e;
return a;
}
}
SMVEC page no.:
CLIENT :
import java.rmi.*;
import java.io.*;
public class RmiClient
{
public static void main(String ar[]) throws RemoteException
{
try
{
BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
System.out.println("enter the server name or ip address: ");
String s = br.readLine();
String s1= "rmi://"+s+"/server";
CalcInterface ci =(CalcInterface)Naming.lookup(s1);
System.out.println(" 1.Withdraw /n 2.Deposit ");
System.out.println("Enter number:");
int n = Integer.parseInt(br.readLine());
switch(n)
{
case 1:
{
System.out.println("enter the amount to be withdrawed:");
int c=Integer.parseInt(br.readLine());
int withdraw = ci.withdraw(c);
System.out.println("your balance is:" +withdraw);
}
case 2:
{
System.out.println("enter the amount to be deposited:");
int e=Integer.parseInt(br.readLine());
int dep = ci.dep(e);
System.out.println("your balance is:" +dep);
}
default:
{
System.out.println("not a valid option");
}
}
}
catch(Exception i)
{
System.out.println(i);
}
}
}
SMVEC page no.:
SERVER :
import java.rmi.*;
import java.net.*;
public class RmiServer
{
public static void main(String ar[]) throws RemoteException
{
try
{
CalcImpl ci=new CalcImpl();
Naming.rebind("Server",ci);
System.out.println("Server ready");
}
catch(Exception i)
{
System.out.println(i);
}
}
}
SMVEC page no.:
SERVER :
CLIENT :