0% found this document useful (0 votes)
21 views

Remote Method Invocation - Atm: Smvec

This document describes a remote method invocation (RMI) system for an ATM. It includes interfaces, implementations, and clients for depositing and withdrawing funds from an account remotely. The interface defines withdraw and deposit methods. The implementation extends the interface and manages the account balance. The client looks up and invokes methods on the remote object to perform transactions, displaying the updated balance. The server binds the implementation object to allow remote access.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Remote Method Invocation - Atm: Smvec

This document describes a remote method invocation (RMI) system for an ATM. It includes interfaces, implementations, and clients for depositing and withdrawing funds from an account remotely. The interface defines withdraw and deposit methods. The implementation extends the interface and manages the account balance. The client looks up and invokes methods on the remote object to perform transactions, displaying the updated balance. The server binds the implementation object to allow remote access.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

SMVEC page no.

:

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 :

You might also like