Use connection less protocol for client server communication in the following pr
ID: 3538413 • Letter: U
Question
Use connection less protocol for client server communication in the following problem.
A banking system consists of a server and some Automated Teller Machines (ATM). The
server manages all user account information. A customer can invoke the following operations
at an ATM.%uF0D8 boolean deposit(int accnt, int amt): this operation increases the balance of user
account accnt by amt, and returns 1 if the operation is successful else return 0.
%uF0D8 float withdraw(int accnt, int amt): this operation decreases the balance of user
account accnt by amt, and returns the amount withdrawn.
%uF0D8 float inquiry(int accnt): this operation returns the balance of user account accnt.
For simplicity, in this assignment you do not need to consider the synchronization problem.
The assignment is constructed in two parts. In the first part, you implement your APIs using a
client/server paradigm in which the two processes communicate using sockets in Java. The
client is the process performing the above operations. The server receives the operation
requests and performs them on behalf of the client. The client and server may (or may not) be
running on separate machines.
Design Requirement:
You should write two programs, a server (bankserver.java) and a client (atmclient.java); the
two should be compiled separately, so that they each have their own executables. The two
processes will communicate with each other using sockets. Your APIs will have client side
and server side implementations with message passing via sockets connecting the two. You
must decide the request/response message formats. Also you have to create a shutdown
routine to free resources. The client API will accept the input parameters, pack them into a
message, send the message to the server, and wait for the reply. When the reply is received, it
extracts the return parameters from the message and returns them to the caller. The server
process should accept() an incoming connection request (after creating, binding, and listening
on the socket), extract the parameters from the message and make the requested call.
Demonstration:
Initially, assume that the Bank server has the following data in its database.
Account
CITI100
CITI522
CITI434
CITI654
CITI767
Balance (INR)
1000
6544
3456
8742
7675
Start the banking server on port 15555:
$bankserver 15555
Test the ATM client:
$atmclient bankserver 15555 inquiry CITI100
Where
%uF0D8
%uF0D8
%uF0D8
%uF0D8
%uF0D8
atmclient is your client process
bankserver hostname of the server
15555 is the port number server is running on
inquiry is the operation to be performed
CITI100 is the account number
Output of inquiry: The current balance of user CITI100 is Rs 1000.00 onlySimilarly test other operations as well
$atmclient bankserver 15555 deposit CITI100 200
Successfully deposit Rs 200.00 to account CITI100
$atmclient bankserver 15555 withdraw CITI100 50
Successfully withdraw Rs 50.00 from account CITI100
Deliverables
The deliverables of the assignment are: atmclient.java, and bankserver.java. The code should
be well commented and documented and should cover most of the error conditions.
Explanation / Answer
For a simplistic demonstration of the operations of the various methods a beginning format provided will be expanded upon. Records for this example will be generated for validating performance but the true end state would be storing records in an Oracle database. Database implementation can be easily achieved using the JDBC ODBC driver provided with Java.
In order to support distributed objects in Java, a remote method invocation (RMI) system that is specifically tailored to operate in the Java environment will be used. Other RMI systems exist (such as CORBA) that can be adapted to handle Java objects, but these systems fall short of seamless integration due to their inter-operability requirement with other languages. Java language%u2019s RMI system assumes the homogeneous environment of the Java Virtual Machine, and the system can therefore follow the Java object model whenever possible.
In my model, a remote object is one whose methods can be accessed from another address space, potentially on a different machine. This is done by logging into two different sessions on NOVA. An object of this type is described by a remote interface, which is an interface that declares the methods of a remote object. RMI is the action of
invoking a method on a remote object. Most importantly, a method invocation on a remote object has the same syntax as a method invocation on a local object. Clients of remote objects program to remote interfaces, not to the implementation classes of those interfaces. Since the failure modes of accessing remote objects are inherently different than the failure semantics of local objects, clients must deal with an additional exception that can occur during any remote method invocation.
In order to implement a remote object, one must first define a remote interface for that object. A remote interface must extend (either directly or indirectly) a distinguished interface called java.rmi.Remote. This interface is completely abstract and has no methods. interface Remote {} For example, the following code fragment defines a
remote interface for a bank account that contains methods that deposit to the account, withdraw from the account, and get the account balance:
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface IAccount extends Remote {
public void deposit(int amount) throws RemoteException;
public void withdraw(int amount) throws RemoteException;
public int getBalance() throws RemoteException;
}
As shown above, each method declared in an interface for a remote object must include java.rmi.RemoteException in its throws clause. If RemoteException is thrown during a remote call, then some communication failure happened during the call. Remote objects
have very different failure semantics than local objects.
For a client to invoke a method on a remote object, that client must first obtain a reference to the object. A reference to a remote object is obtained in the usual
manner: as a return value in a method call or as a parameter passed to a method. The RMI system provides a simple bootstrap name server from which to obtain remote objects on given hosts. Since remote methods include RemoteException in their signature, the caller must be prepared to handle those exceptions in addition to other application specific exceptions. So, for each of the calls (deposit, withdraw, and balance), the code needs to catch RemoteException.
A simple bootstrap name server is provided for storing named references to remote objects. A remote object reference can be stored using the URL-based interface java.rmi.Naming. For a client to invoke a method on a remote object, that client must first obtain a reference to the object. A reference to a remote object is usually obtained as a
return value in a method call. The RMI system provides a simple bootstrap name server from which to obtain remote objects on given hosts. The Naming interface provides Uniform Resource Locator (URL) based methods to lookup, bind, rebind, unbind and list
the name and object pairings maintained on a particular host and port. Here's an example of how to bind and lookup remote objects:
public static void main(String[] args) throws MalformedURLException, RemoteException, NotBoundException {
String url = "rmi://localhost/Account";
IAccount account = (IAccount)Naming.lookup(url);
}
public class AccountServer {
public static void main(String[] args) throws RemoteException, MalformedURLException {
System.out.println("starting the server");
Account m = new Account();
Naming.rebind("Account", m);
}
}
nova> dir
accountrmi cmis445
nova> ant
Buildfile: build.xml does not exist!
Build failed
nova> cd accountrmi
nova> ant
Buildfile: build.xml
property.setup:
clean.dirs:
[delete] Deleting: /class/cm445a/07/accountrmi/accountrmi.jar
build.java:
build.all:
[jar] Building jar: /class/cm445a/07/accountrmi/accountrmi.jar
BUILD SUCCESSFUL
Total time: 3 seconds
nova> rmiregistry &
[1] 15245
nova> ant startaccountserver
Buildfile: build.xml
property.setup:
startaccountserver:
[java] starting the server
[java] account was made
[java] after name rebind.
nova> dir
accountrmi cmis445
nova> cd accountrmi
nova> ant startaccountclient
Buildfile: build.xml
property.setup:
startaccountclient:
[java] Working directory ignored when same JVM is used.
[java] Owner Name: Tom Jones
[java] Social Security Num: 123-45-6789
[java] Address: 15 South St. Aiea, HI96789
[java] Phone Number: 808-345-6789
[java] Email: cfsmith@earthlink.net
[java] check cur balance: 0
[java] check cur balance: 100
[java] cur balance: 50
[java] saving cur balance: 0
[java] saving cur balance: 1000
[java] saving cur balance: 850
[java] All accounts: Current checking account balance is 50 and savings account balance is 850
[java] Information: Account owner information:
[java] Tom Jones
[java] 15 South St. Aiea, HI96789
[java] 808-345-6789
[java] cfsmith@earthlink.net
[java] 123-45-6789
BUILD SUCCESSFUL
Total time: 4 seconds
nova>
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.