CL IX Lab Manual - 2021 22
CL IX Lab Manual - 2021 22
LAB MANUAL
CLASS: BE-IT
SEMESTER: II
TEACHING SCHEME
INDEX
Sr. Content Page no.
No
.
1 Department vision ,Mission, Program Educational 4
Objectives , Program Specific Outcomes and Program
Outcomes
2 SPPU course objective and outcome 7
3 Department course objective and outcome 8
4 SPPU suggested List of Laboratory Assignments 11
5 Department conducted list of laboratory assignments 12
6 Assignment No: 1 14
7 Assignment No: 2 25
8 Assignment No: 3 30
9 Assignment No: 4 41
10 Assignment No: 5 45
11 Assignment No: 6 50
12 Assignment No: 7 58
14 References
Vision
To equip students with core and state of the art Information Technologies.
Mission
Program Outcomes
Prerequisites:
1. Operating Systems.
2. Computer Network Technology.
Course Objectives:
Course Outcomes:
Course Objectives
CO-PO-PSO Mapping:
CO
C406.1 3 2 2 2 1
C406.2 3 2 3 2 2 2 2 3
C406.3 3 2 2 2 2 2 1
C406.4 3 2 2 2 2 2 2 1 1 1
C406.5 3 2 2 2 1
C406.6 2 2 1 3 2 2 1 1 1
Avg. 2.5 1.66 1.83 0.66 0.66 0.16 - 0.5 2 2 0.16 0.16 1.5 0.5
Related Theory:
Socket: In distributed computing, network communication is one of the essential
parts of any system, and the socket is the endpoint of every instance of network
communication. In Java communication, it is the most critical and basic object
involved.
A socket is a handle that a local program can pass to the networking API to
connect to another machine. It can be defined as the terminal of a communication
link through which two programs /processes/threads running on the network can
communicate with each other. The TCP layer can easily identify the application
location and access information through the port number assigned to the respective
sockets.
The java.net package provides support for the two common network protocols −
UDP − UDP stands for User Datagram Protocol, a connection-less protocol that
allows for packets of data to be transmitted between applications.
The following steps occur when establishing a TCP connection between two
computers using sockets −
Client Programming:
Server Programming:
4. Type messages in the Client Window which will be received and showed by
the Server Window simultaneously if you are developing echo server
application.
Related Theory:
The following diagram shows how RMI happens between the RMI client and RMI
server with the help of the
RMI registry:
Remote interface: This is a Java interface that defines the methods that exist in a
remote object. A remote object can implement more than one remote interface to
adopt multiple remote interface behaviors.
RMI: This is a way of invoking a remote object's methods with the help of a remote
interface. It can be carried with a syntax that is similar to the local method
invocation.
Stub: This is a Java object that acts as an entry point for the client object to route
any outgoing requests. It exists on the client JVM and represents the handle to the
remote object.
If any object invokes a method on the stub object, the stub establishes RMI by
following these steps:
2. Ensure that the components that participate in the RMI calls are accessible across
networks.
3. Establish a network connection between applications that need to interact using
the RMI.
2. Remote object implementation: Java allows a class to implement more than one
interface at a time. This helps remote objects implement one or more remote
interfaces. The remote object class may have to implement other local interfaces and
methods that it is responsible for. Avoid adding complexity to this scenario, in terms
3. Remote client implementation: Client objects that interact with remote server
objects can be written once the remote interfaces are carefully defined even after the
remote objects are deployed.
Let's design a project that can sit on a server. After that different client projects
interact with this project to pass the parameters and get the computation on the
remote object execute and return the result to the client components.
The server receives a request from a client, processes it, and returns a result. In this
example, the request specifies two numbers. The server adds these together and
returns the sum.
This application uses four source files. The first file, AddServerIntf.java, defines
the remote interface that is provided by the server. It contains one method that
accepts two double arguments and returns their sum. All remote interfaces must
extend the Remote interface, which is part of java.rmi. Remote defines no
members. Its purpose is simply to indicate that an interface uses remote methods.
All remote methods can throw a RemoteException.
The second source file, AddServerImpl.java, implements the remote interface. The
implementation of the add() method is straightforward. All remote objects must
extend UnicastRemoteObject, which provides functionality that is needed to make
objects available from remote machines.
Use javac to compile the four source files that are created.
2. Generate a Stub
Before using client and server, the necessary stub must be generated. In the context
of RMI, a stub is a Java object that resides on the client machine. Its function is to
present the same interfaces as the remote server. Remote method calls initiated by
the client are actually directed to the stub. The stub works with the other parts of the
RMI system to formulate a request that is sent to the remote machine.
All of this information must be sent to the remote machine. That is, an object passed
as an argument to a remote method call must be serialized and sent to the remote
machine. If a response must be returned to the client, the process works in reverse.
The serialization and deserialization facilities are also used if objects are
returned to a client.
To generate a stub the command is RMIcompiler is invoked as follows:
rmic AddServerImpl.
AISSMS IOIT, Department of Information Technology Page 23
This command generates the file AddServerImpl_Stub.class.
The server code is started from the command line, as shown here:
java AddServer
The AddServer code instantiates AddServerImpl and registers that object with the
name “AddServer”.
6. Start the Client
The AddClient software requires three arguments: the name or IP address of the
server machine and the two numbers that are to be summed together. You may
invoke it from the command line by using one of the two formats shown here:
java AddClient 192.168.13.14 7 8
Conclusion:
Remote Method Invocation (RMI) allows you to build Java applications that
are distributed among several machines. Remote Method Invocation (RMI) allows
a Java object that executes on one machine to invoke a method of a Java object that
executes on another machine. This is an important feature, because it allows you to
build distributed applications.
Currently developers can produce more efficient and effective parallel applications
using message passing.
A basic prerequisite for message passing is a good communication API. Java comes
with various ready-made packages for communication, notably an interface to BSD
sockets, and the Remote Method Invocation (RMI) mechanism. The parallel
computing world is mainly concerned with `symmetric' communication, occurring
in groups of interacting peers. This symmetric model of communication is captured
in the successful Message Passing Interface standard (MPI).
The mpi.h file contains the definitions and declarations necessary for compiling an
MPI program.
The principal weakness of this limited form of processing is that the processes on
different nodes run entirely independent of each other. It cannot enable capability or
coordinated computing. To get the different processes to interact, the concept of
communicators is needed. MPI programs are made up of concurrent processes
executing at the same time that in almost all cases
are also communicating with each other. To do this, an object called the
“communicator” is provided by MPI. Thus the user may specify any number of
communicators within an MPI program, each with its own set of processes.
“MPI_COMM_WORLD” communicator contains all the concurrent processes
making up an MPI program.
The size of a communicator is the number of processes that makes up the particular
communicator. The following function call provides the value of the number of
processes of the specified communicator:
int MPI_Comm_size(MPI_Comm comm, int _size).
The send function is used by the source process to define the data and establish
the connection of the message. The send construct has the following syntax:
The first three operands establish the data to be transferred between the source and
destination processes. The first argument points to the message content itself, which
may be a simple scalar or a group of data. The message data content is described by
the next two arguments. The second operand specifies the number of data elements
of which the message is composed. The third operand indicates the data type of the
elements that make up the message.
The receive command (MPI_Recv) describes both the data to be transferred and the
connection to be established. The MPI_Recv construct is structured as follows:
int MPI_Recv (void _message, int count, MPI_Datatype datatype, int source,
int tag, MPI_Comm comm, MPI_Status _status)
The source field designates the rank of the process sending the message.
The multicore configuration is meant for users who plan to write and execute parallel
Java applications using MPJ Express on their desktops or laptops which contains
shared memory and multicore processors. In this configuration, users can write their
message passing parallel application using MPJ Express and it will be ported
automatically on multicore processors. We except that users can first develop
applications on their laptops and desktops using multicore configuration, and then
take the same code to distributed memory platforms
While designing the solution, we have considered the multi-core architecture as per
shown in the diagram below. The communicator has processes as per input by the
user. MPI program will execute the sequence as per the supplied processes and the
number of processor cores available for the execution.
c. export MPJ_HOME=/path/to/mpj/
d. export PATH=$MPJ_HOME/bin:$PATH
2. Write Hello World parallel Java program and save it as HelloWorld.java
(Asign2.java).
3. Compile a simple Hello World (Asign) parallel Java program
Conclusion:
There has been a large amount of interest in parallel programming using Java. mpj
is an MPI binding with Java along with the support for multicore architecture so that
user can develop the code on it's own laptop or desktop. This is an effort to develop
and run parallel programs according to MPI standard.
Tools / Environment:
Related Theory:
Except legacy applications, most of the applications follow common standards when
it comes to object modeling, for example. All applications related to, say,
"HR&Benefits" maintain an object model with details of the organization,
The contract between these applications is defined in terms of an interface for the
server objects that the clients can call. This IDL interface is used by each client to
indicate when they should call any particular method to marshal (read and send the
arguments).
The target object is going to use the same interface definition when it receives the
request from the client to unmarshal (read the arguments) in order to execute the
method that was requested by the client operation. Again, during response handling,
the interface definition is helpful to marshal (send from the server) and unmarshal
(receive and read the response) arguments on the client side once received.
The IDL interface is a design concept that works with multiple programming
languages including C, C++, Java, Ruby, Python, and IDLscript. This is close to
writing a program to an interface, a concept we have been discussing that most recent
programming languages and frameworks, such as Spring. The interface has to be
defined clearly for each object. The systems encapsulate the actual implementation
along with their respective data handling and processing, and only the methods are
available to the rest of the world through the interface. Hence, the clients are forced
to develop their invocation logic for the IDL interface exposed by the application
they want to connect to with the method parameters (input and output) advised by
the interface operation.
The following diagram shows a single-process ORB CORBA architecture with the
IDL configured as client stubs with object skeletons, The objects are written (on the
right) and a client for it (on the left), as represented in the diagram. The client and
server use stubs and skeletons as proxies, respectively. The IDL interface follows a
strict definition, and even though the client and server are implemented in different
technologies, they should integrate smoothly with the interface definition strictly
implemented.
Inter-ORB communication
The following diagram shows how remote invocation works for inter-ORB
communication. It shows that the clients that interacted have created IDL Stub and
IDL Skeleton based on Object Request Broker and communicated through IIOP
Protocol.
The ORB is a runtime component that can be used for distributed computing
using IIOP communication. Java IDL is a Java API for interoperability and
integration with CORBA. Java IDL included both a Java-based ORB, which
supported IIOP, and the IDL-to-Java
compiler, for generating client-side stubs and server-side code skeletons. J2SE
v.1.4 includes an
When using the IDL programming model, the interface is everything! It defines
the points of entry that can be called from a remote process, such as the types of
arguments the called procedure will accept, or the value/output parameter of
information returned. Using IDL, the programmer can make the entry points and
data types that pass between communicating processes act like a standard language.
With RMI, the interface and the implementation language are described in the same
language, so you don't have to worry about mapping from one to the other.
Language-level objects (the code itself) can be passed from one process to the next.
Values can be returned by their actual type, not the declared type. Or, you can
compile the interfaces to generate IIOP stubs and skeletons which allow your objects
to be accessible from other CORBA-compliant languages.
The IDL programming model, known as Java™ IDL, consists of both the Java
CORBA ORB and the idlj compiler that maps the IDL to Java bindings that use the
Java CORBA ORB, as well as a set of APIs, which can be explored by selecting the
org.omg prefix from the Package section of the API index.
Java IDL adds CORBA (Common Object Request Broker Architecture) capability
to the Java platform, providing standards-based interoperability and connectivity.
Runtime components include a Java ORB for distributed computing using IIOP
communication.
To use the IDL programming model, define remote interfaces using OMG Interface
Definition Language (IDL), then compile the interfaces using idlj compiler. When
you run the idlj compiler over your interface definition file, it generates the Java
version of the interface, as well as the class code files for the stubs and skeletons that
enable applications to hook into the ORB.
1.1. In order to distribute a Java object over the network using CORBA, one
has to define it's own CORBA-enabled interface and it implementation. This
involves doing the following:
Generating a Java base interface, plus a Java stub and skeleton class, using
an IDL-to-Java compiler
1.2. Modules
Modules are declared in IDL using the module keyword, followed by a name for the
module and an opening brace that starts the module scope. Everything defined within
the scope of this module (interfaces, constants, other modules) falls within the
module and is referenced in other IDL modules using the syntax modulename::x.
e.g.
};
};
1.3. Interfaces
This header starts the declaration of an interface called PrintServer that inherits all
the methods and data members from the Server interface.
1.4 Data members and methods
The interface body declares all the data members (or attributes) and methods of an
interface. Data members are declared using the attribute keyword. At a minimum,
the declaration includes a name and a type.
readonly attribute string myString;
The method can be declared by specifying its name, return type, and parameters, at
a minimum. string parseString(in string buffer);
This declares a method called parseString() that accepts a single string argument and
returns a string value.
module OS {
module services {
interface Server {
};
interface Printable {
};
};
};
};
The first interface, Server, has a single read-only string attribute and an init() method
that accepts a string and returns a boolean. The Printable interface has a single
print()method that accepts a string header. Finally, the PrintServer interface extends
the Server interface and adds a printThis() method that accepts a Printable object and
returns a boolean. In all cases, we've declared the method arguments as input-only
(i.e., pass-by-value), using the in keyword.
2. Turning IDL Into Java
A Java interface with the same name as the IDL interface. This can act as the
basis for a Java implementation of the interface (but you have to write it, since
IDL doesn't provide any details about method implementations).
A holder class whose name is the name of the IDL interface with "Holder"
appended to it
(e.g., ServerHolder). This class is used when objects with this interface are used
as out or inout arguments in remote CORBA methods. Instead of being passed
directly into the remote method, the object is wrapped with its holder before being
passed. When a remote method has parameters that are declared as out or inout,
the method has to be able to update the argument it is passed and return the
updated value. The only way to guarantee this, even for primitive Java data types,
is to force out and inout arguments to be wrapped in Java holder classes, which
are filled with the output value of the argument when the method returns.
So, in addition to generating a Java mapping of the IDL interface and some helper
classes for the Java interface, the idltoj compiler also creates subclasses that act as
an interface between a CORBA client and the ORB and between the server-side
implementation and the ORB.
Tools / Environment:
Assumptions:
Each process has a unique number to distinguish them. Processes know each other's
process number.\
There are two types of Distributed Algorithms:
1. Bully Algorithm
2. Ring Algorithm
Bully Algorithm:
1. It holds an election.
2. If it happens to be the highest process currently running, it will win the
election and take over the coordinators job.
“Biggest guy" always wins and hence the name bully algorithm.
Ring Algorithm:
Initiation:
1. When a process notices that coordinator is not functioning:
2. Another process (initiator) initiates the election by sending "ELECTION" message
(containing its own process number)
Leader Election:
3. Initiator sends the message to it's successor (if successor is down, sender skips
over it and goes to the next member along the ring, or the one after that, until a
running process is located).
4. At each step, sender adds its own process number to the list in the message.
5. When the message gets back to the process that started it all: Message comes back
to initiator. In the queue the process with maximum ID Number wins.
Initiator announces the winner by sending another message around the ring.
Initiation:
4. Initiator announces the winner by sending another message around the ring. Here
the process with highest process ID is 6. The initiator will announce that Process 6
is Coordinator.
3. Getting input from User for number of Processes and store them into object of
classes.
Conclusion:
To create a simple web service and write any distributed application to consume
the web service.
Tools / Environment:
Related Theory:
Web Service:
The service is open to, and not tied to, any operating system/programming
language
1. SOAP: SOAP stands for Simple Object Access Protocol. SOAP is an XML
based industry standard protocol for designing and developing web services.
Since it’s XML based, it’s platform and language independent. So, our server
can be based on JAVA and client can be on NET, PHP etc. and vice versa.
Service Provider is the program that implements the service agreed for the web
service and exposes the service over the internet/intranet for other applications to
interact with.
Service Requestor is the program that interacts with the web service exposed by the
Service Provider. It makes an invocation to the web service over the network to the
Service Provider and exchanges information.
Service Registry acts as the directory to store references to the web services.
The following are the steps involved in a basic SOAP web service operational
behavior:
1. The client program that wants to interact with another application prepares its
request content as a SOAP message.
2. Then, the client program sends this SOAP message to the server web service
as an HTTP POST request with the content passed as the body of the request.
3. The web service plays a crucial role in this step by understanding the SOAP
request and converting it into a set of instructions that the server program can
understand.
4. The server program processes the request content as programmed and
prepares the output as the response to the SOAP request.
5. Then, the web service takes this response content as a SOAP message and
reverts to the SOAP HTTP request invoked by the client program with this
response.
6. The client program web service reads the SOAP response message to receive
the outcome of the server program for the request content it sent as a request.
While XML and HTTP together make the basic platform for web services, the
following are the key components of standard SOAP web services:
Universal Description, Discovery, and Integration (UDDI): UDDI is an
XMLbased framework for describing, discovering, and integrating web services. It
acts as a directory of web service interfaces described in the WSDL language.
Web Services Description Language (WSDL): WSDL is an XML document
containing information about web services, such as the method name, method
parameters, and how to invoke the service. WSDL is part of the UDDI registry. It
acts as an interface between applications that want to interact based on web services.
The following diagram shows the interaction between the UDDI, Service Provider,
and service consumer in SOAP web services:
Conclusion:
This assignment, described the Web services approach to the Service Oriented
Architecture concept. Also, described the Java APIs for programming Web services
and demonstrated examples of their use by providing detailed step-by-step examples
of how to program Web services in Java.
Related Theory:
EMS, or the messaging system, defines system standards for organizations so they
can define their enterprise application messaging process with a semantically precise
messaging structure. EMS encourages you to define a loosely coupled application
architecture in order to define an industry-accepted message structure; this is to
ensure that published messages would be persistently consumed by subscribers.
Common formats, such as XML or JSON, are used to do this. EMS recommends
these messaging protocols: DDS, MSMQ, AMQP, or SOAP web services. Systems
designed with EMS are termed Message-Oriented Middleware (MOM). An
asynchronous communication is used while messaging in EMS.
JMS providing a standard, portable way for Java programs to send/receive messages
through a MOM product. Any application written in JMS can be executed on any
MOM that implements the JMS API standards. The JMS API is specified as a set of
interfaces as part of the Java API. Hence, all the products that intend to provide JMS
behavior will have to deliver the provider to implement JMS-defined interfaces.
With programming patterns that allow a program to interface, you should be able to
construct a Java application in line with the JMS standards by defining the
messaging programs with client applications to exchange information through JMS
messaging.
The publish/subscribe messaging paradigm is built with the concept of a topic, which
behaves like an announcement board. Consumers subscribe to receiving messages
that belong to a topic, and publishers report messages to a topic. The JMS provider
retains the responsibility for distributing the messages that it receives from multiple
publishers to many other subscribers based on the topic they subscribe to. A
subscriber receives messages that it subscribes to based on the rules it defines and
the messages that are published after the subscription is registered; they do not
receive any messages that are already published, as shown in the following diagram:
JMS interfaces
In designing our solution, we have created one publisher and subscriber wherein the
publisher creates topic.
The Publisher/Subscriber pattern is mostly implemented in an asynchronous way (using
message queue).
JMS is a Java API that allows applications to create, send, receive, and read
messages. The JMS API enables communication that is loosely coupled,
asynchronous and reliable.
To use JMS, we need to have a JMS provider that can manage the sessions, queues,
and topics. Some examples of known JMS providers are Apache ActiveMQ,
WebSphere MQ from IBM or SonicMQ from Aurea Software. Starting from Java
EE version 1.4, a JMS provider has to be contained in all Java EE application servers.
JMS messages are objects that communicate information between JMS clients and
are composed of a header, some optional properties, and an optional body.
1. To execute the pub-sub programs, you need the message queue environment.
The Java Message Service (JMS) API is a Java Message Oriented Middleware
(MOM) API for sending messages between two or more clients. It is a Java API
that allows applications to create, send, receive, and read messages. The JMS
API enables communication that is loosely coupled, asynchronous and reliable.
To use JMS, we need to have a JMS provider that can manage the sessions,
queues, and topics. Some examples of known JMS providers are Apache
ActiveMQ, WebSphere MQ from IBM or SonicMQ from Aurea Software.
Here we are implementing the JMS concepts and illustrates them with a JMS
Hello World example using ActiveMQ.
Interfaces extending core JMS interfaces for Topic help build publish-subscribe
components.
Conclusion:
Tools / Environment:
Related Theory:
1. Microservices:
A team designing a microservices architecture for their application will split all
of the major functions of an application into independent services. Each
Independently deployable
Organized around business capabilities.
2. Web frameworks encapsulate what developers have learned over the past twenty
years while programming sites and applications for the web. Frameworks make it
easier to reuse code for common HTTP operations and to structure projects so other
developers with knowledge of the framework can quickly build and maintain the
application.
1. URL routing
2. Input form handling and validation
3. HTML, XML, JSON, and other output formats with a templating engine
4. Database connection configuration and persistent data manipulation through an
object-relational mapper (ORM)
5. Web security against Cross-site request forgery (CSRF), SQL Injection, Cross-
site Scripting (XSS) and other common malicious attacks
3. Flask (source code) is a Python web framework built with a small core and easy-
to-extend philosophy. Flask is based on the Werkzeug WSGI toolkit and Jinja2
template engine.
4. WSGI: Web Server Gateway Interface (WSGI) has been adopted as a standard
for Python web application development. WSGI is a specification for a universal
interface between the web server and the web applications.
6. Virtual Environment:
In Python, by default, every project on the system will use the same directories to
store and retrieve site packages (third party libraries). and system packages
(packages that are part of the standard Python library). Consider the a scenario where
there are two projects: ProjectA and ProjectB, both of which have a dependency on
the same library, ProjectC. The problem becomes apparent when we start requiring
different versions of ProjectC. Maybe ProjectA needs v1.0.0, while ProjectB
requires the newer v2.0.0, for example.
Since projects are stored in site-packages directory according to just their name and
can't differentiate between versions, both projects, ProjectA and ProjectB, would be
required to use the same version which is unacceptable in many cases and hence the
virtual environment. The
Route decorator:
For example −
@app.route(‘/hello’)
def hello_world():
Here, URL ‘/hello’ rule is bound to the hello_world() function. As a result, if a user
visits http://localhost:5000/hello URL, the output of the hello_world() function will
be rendered in the browser.
3. Writing the subroutine for the four microservices: There are four
microservices viz., user, Showtimes, Bookings and Movies for which
microservices are to be implemented.
Conclusion: