UNIT-2 by Satish
UNIT-2 by Satish
By
Satish Dekka,
Associate Professor
Department of CSE,
Lendi Institute of Engineering and Technology
Contents:
• Introduction
• The API for the Internet Protocols
• The Characteristics of Interprocess communication
• Sockets
• UDP Datagram Communication
• TCP Stream Communication
• External Data Representation and Marshalling
• Client Server Communication
• Group Communication- IP Multicast- an implementation of
group communication
• Reliability and Ordering of Multicast.
Introduction
Interprocess Communication is a process of exchanging the data between two
or more independent process in a distributed environment is called as
Interprocess communication. Interprocess communication on the internet
provides both Datagram and stream communication.
Examples Of Interprocess Communication:
1. N number of applications can communicate with the X server through
network protocols.
2. Servers like Apache spawn child processes to handle requests.
3. Pipes are a form of IPC: grep foo file | sort
It has two functions:
4. Synchronization:
Exchange of data is done synchronously which means it has a single clock
pulse.
5. Message Passing:
When processes wish to exchange information. Message passing takes
several forms such as: pipes, FIFO, Shared Memory, and Message Queues.
Characteristics of Inter-process
Communication:
There are mainly five characteristics of inter-process communication in a distributed environment/system.
1. Synchronous System Calls:
In the synchronous system calls both sender and receiver use blocking system calls to transmit the data which
means the sender will wait until the acknowledgment is received from the receiver and receiver waits until the
message arrives.
2. Asynchronous System Calls:
In the asynchronous system calls, both sender and receiver use non-blocking system calls to transmit the data which
means the sender doesn’t wait from the receiver acknowledgment.
3. Message Destination:
A local port is a message destination within a computer, specified as an integer. Aport has exactly one receiver but
many senders. Processes may use multiple ports from which to receive messages. Any process that knows the
number of a port can send the message to it.
4. Reliability:
It is defined as validity and integrity.
5. Integrity:
Messages must arrive without corruption and duplication to the destination.
6. Validity:
Point to point message services are defined as reliable, If the messages are guaranteed to be delivered without being
lost is called validity.
7. Ordering:
It is the process of delivering messages to the receiver in a particular order. Some applications require messages to
be delivered in the sender order i.e the order in which they were transmitted by the sender.
INTERPROCESS COMMUNICATION
Introduction
The java API for interprocess communication in the internet
provides both datagram and stream communication.
The two communication patterns that are most commonly
used in distributed programs:
Client-Server communication
The request and reply messages provide the basis for remote
method invocation (RMI) or remote procedure call (RPC).
Group communication
The same message is sent to several processes.
Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005
5
INTERPROCESS COMMUNICATION
Introduction
Remote Method Invocation (RMI)
It allows an object to invoke a method in an object in a
remote process.
E.g. CORBA and Java RMI
Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005
6
INTERPROCESS COMMUNICATION
Introduction
This chapter is concerned with
middleware.
Introduction
The application program interface
(API) to UDP provides a message passing abstraction.
Message passing is the simplest form of interprocess
communication.
API enables a sending process to transmit a single
message to a receiving process.
The independent packets containing theses messages
are called datagrams.
In the Java and UNIX APIs, the sender specifies the
destination using a socket.
Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005
8
INTERPROCESS COMMUNICATION
Introduction
Socket is an indirect reference to a particular port
used by the destination process at a destination
computer.
The application program interface (API) to TCP
provides the abstraction of a two-way stream
between pairs of processes.
The information communicated consists of a
stream of data items with no message
boundaries.
Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005
9
INTERPROCESS COMMUNICATION
Introduction
Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005
10
INTERPROCESS COMMUNICATION
SOCKET
UDP DATAGRAM COMMUNICATION
TCP STREAM COMMUNICATION
Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005
11
INTERPROCESS COMMUNICATION
Sockets
Internet IPC mechanism of Unix and other operating systems (BSD Unix, Solaris, Linux,
Windows NT, Macintosh OS)
Processes in the above OS can send and receive messages via a socket.
Sockets need to be bound to a port number and an internet address in order to send and
receive messages.
Each socket has a transport protocol (TCP or UDP).
Messages sent to some internet address and port number can only be received by a
process using a socket that is bound to this address and port number.
Processes cannot share ports (exception: TCP multicast).
Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005
12
INTERPROCESS COMMUNICATION
Sockets
Both forms of communication, UDP and TCP, use the
socket abstraction, which provides and endpoint for
communication between processes.
Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005
13
INTERPROCESS COMMUNICATION
Sockets
Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005
15
INTERPROCESS COMMUNICATION
Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005 16
INTERPROCESS COMMUNICATION
Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005
17
INTERPROCESS COMMUNICATION
array of bytes containing message | length of message| Internet address | port number|
18
Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005
INTERPROCESS COMMUNICATION
Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005
19
INTERPROCESS COMMUNICATION
Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005
20
INTERPROCESS COMMUNICATION
Figure 3. UDP client sends a message to the server and gets a reply
Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005
21
INTERPROCESS COMMUNICATION
Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005
22
INTERPROCESS COMMUNICATION
Figure 4. UDP server repeatedly receives a request and sends it back to the client
Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005
23
INTERPROCESS COMMUNICATION
Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005
24
INTERPROCESS COMMUNICATION
Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005
25
INTERPROCESS COMMUNICATION
Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005
26
INTERPROCESS COMMUNICATION
Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005
27
INTERPROCESS COMMUNICATION
Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005
28
INTERPROCESS COMMUNICATION
Figure 6. TCP server makes a connection for each client and then echoes the client’s
requestCouloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005
29
INTERPROCESS COMMUNICATION
Figure 7. TCP server makes a connection for each client and then echoes the client’s
request Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005
30
INTERPROCESS COMMUNICATION
Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005
31
INTERPROCESS COMMUNICATION
Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005
32
INTERPROCESS COMMUNICATION
Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005
33
INTERPROCESS COMMUNICATION
Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005
34
INTERPROCESS COMMUNICATION
Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005
35
INTERPROCESS COMMUNICATION
Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005
36
INTERPROCESS COMMUNICATION
Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005
38
INTERPROCESS COMMUNICATION
Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005
39
INTERPROCESS COMMUNICATION
Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005
41
INTERPROCESS COMMUNICATION
Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005
43
INTERPROCESS COMMUNICATION
Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005
45
INTERPROCESS COMMUNICATION
Client-Server Communication
Often built over UDP datagrams
Client-server protocol consists of
request/response pairs, hence no
acknowledgements at transport layer are
necessary
Avoidance of connection establishment
overhead
No need for flow control due to small amounts
of data are transferred
Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005
46
INTERPROCESS COMMUNICATION
Client-Server Communication
The request-reply protocol was based on a trio
of communication primitives: doOperation,
getRequest, and sendReply shown in Figure 12.
Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005
47
INTERPROCESS COMMUNICATION
Client-Server Communication
The request-reply protocol is shown in Figure 12.
Client-Server Communication
The designed request-reply protocol matches requests to
replies.
If UDP datagrams are used, the delivery guarantees
must be provided by the request-reply protocol, which
may use the server reply message as an
acknowledgement of the client request message.
Figure 13 outlines the three communication primitives.
Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005
49
INTERPROCESS COMMUNICATION
Client-Server Communication
Client-Server Communication
The information to be transmitted in a request
message or a reply message is shown in Figure 14.
Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005
51
INTERPROCESS COMMUNICATION
Client-Server Communication
In a protocol message
The first field indicates whether the message is a
request or a reply message.
The second field request id contains a message
identifier.
The third field is a remote object reference .
The fourth field is an identifier for the method to
be invoked.
Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005
52
INTERPROCESS COMMUNICATION
Client-Server Communication
Message identifier
A message identifier consists of two parts:
A requestId, which is taken from an
increasing sequence of integers by the
sending process
An identifier for the sender process, for
example its port and Internet address.
Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005
53
INTERPROCESS COMMUNICATION
Client-Server Communication
Failure model of the request-reply protocol
If the three primitive doOperation,
getRequest, and sendReply are
implemented over UDP datagram, they
have the same communication failures.
Omission failure
Messages are not guaranteed to be
delivered in sender order.
Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005
54
INTERPROCESS COMMUNICATION
Client-Server Communication
RPC exchange protocols
Three protocols are used for implementing
various types of RPC.
The request (R) protocol.
The request-reply (RR) protocol.
The request-reply-acknowledge (RRA)
protocol.
(Figure 15)
Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005
55
INTERPROCESS COMMUNICATION
Client-Server Communication
Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005
56
INTERPROCESS COMMUNICATION
Client-Server Communication
In the R protocol, a single request message is
sent by the client to the server.
The R protocol may be used when there is no
value to be returned from the remote method.
The RR protocol is useful for most client-server
exchanges because it is based on request-reply
protocol.
RRA protocol is based on the exchange of three
messages: request-reply-acknowledge reply.
Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005
57
INTERPROCESS COMMUNICATION
Client-Server Communication
HTTP: an example of a request-reply
protocol
HTTP is a request-reply protocol for the
exchange of network resources between
web clients and web servers.
Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005
58
INTERPROCESS COMMUNICATION
Client-Server Communication
HTTP protocol steps are:
Connection establishment between client
and server at the default server port or at a
port specified in the URL
client sends a request
server sends a reply
connection closure
Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005
59
INTERPROCESS COMMUNICATION
Client-Server Communication
HTTP 1.1 uses persistent connections.
Persistent connections are connections that
remains open over a series of request-reply
exchanges between client and server.
Resources can have MIME-like structures
in arguments and results.
Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005
60
INTERPROCESS COMMUNICATION
Client-Server Communication
A Mime type specifies a type and a
subtype, for example:
text/plain
text/html
image/gif
image/jpeg
Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005
61
INTERPROCESS COMMUNICATION
Client-Server Communication
HTTP methods
GET
Requests the resource, identified by URL as
argument.
If the URL refers to data, then the web server replies
by returning the data
If the URL refers to a program, then the web server
runs the program and returns the output to the client.
Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005
62
INTERPROCESS COMMUNICATION
Client-Server Communication
HEAD
This method is similar to GET, but only meta
data on resource is returned (like date of
last modification, type, and size)
Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005
63
INTERPROCESS COMMUNICATION
Client-Server Communication
POST
Specifies the URL of a resource (for
instance, a server program) that can deal
with the data supplied with the request.
This method is designed to deal with:
• Providing a block of data to a data-handling
process
• Posting a message to a bulletin board, mailing
list or news group.
• Extending a dataset with an append operation
Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005
64
INTERPROCESS COMMUNICATION
Client-Server Communication
PUT
Supplied data to be stored in the given URL
as its identifier.
DELETE
The server deletes an identified resource by
the given URL on the server.
OPTIONS
A server supplies the client with a list of
methods.
It allows to be applied to the given URL
Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005
65
INTERPROCESS COMMUNICATION
Client-Server Communication
TRACE
The server sends back the request
message
Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005
66
INTERPROCESS COMMUNICATION
Client-Server Communication
A reply message specifies
The protocol version
A status code
Reason
Some headers
An optional message body
Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005
67
INTERPROCESS COMMUNICATION
Group Communication
The pairwise exchange of messages is not
the best model for communication from
one process to a group of other
processes.
A multicast operation is more appropriate.
Multicast operation is an operation that
sends a single message from one process
to each of the members of a group of
processes.
Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005
68
INTERPROCESS COMMUNICATION
Group Communication
The simplest way of multicasting, provides
no guarantees about message delivery or
ordering.
Multicasting has the following
characteristics:
Fault tolerance based on replicated
services
A replicated service consists of a group of
servers.
Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005
69
INTERPROCESS COMMUNICATION
Group Communication
Client requests are multicast to all the
members of the group, each of which
performs an identical operation.
Finding the discovery servers in
spontaneous networking
Multicast messages can be used by servers
and clients to locate available discovery
services in order to register their interfaces
or to look up the interfaces of other services
in the distributed system.
Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005
70
INTERPROCESS COMMUNICATION
Group Communication
Better performance through replicated
data
Data are replicated to increase the
performance of a service.
Propagation of event notifications
Multicast to a group may be used to notify
processes when something happens.
Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005
71
INTERPROCESS COMMUNICATION
Group Communication
IP multicast
IP multicast is built on top of the Internet
protocol, IP.
IP multicast allows the sender to transmit a
single IP packet to a multicast group.
A multicast group is specified by class D IP
address for which first 4 bits are 1110 in
IPv4.
Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005
72
INTERPROCESS COMMUNICATION
Group Communication
The membership of a multicast group is
dynamic.
A computer belongs to a multicast group if
one or more processes have sockets that
belong to the multicast group.
Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005
73
INTERPROCESS COMMUNICATION
Group Communication
The following details are specific to IPv4:
Multicast IP routers
• IP packets can be multicast both on local
network and on the wider Internet.
• Local multicast uses local network such as
Ethernet.
• To limit the distance of propagation of a
multicast datagram, the sender can specify the
number of routers it is allowed to pass- called
the time to live, or TTL for short.
Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005
74
INTERPROCESS COMMUNICATION
Group Communication
Multicast address allocation
• Multicast addressing may be permanent or
temporary.
• Permanent groups exist even when there are no
members.
• Multicast addressing by temporary groups must
be created before use and cease to exit when
all members have left.
• The session directory (sd) program can be used
to start or join a multicast session.
• session directory provides a tool with an
interactive interface that allows users to browse
advertised multicast sessions and to advertise
their own session, specifying the time and
duration.
Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005
75
INTERPROCESS COMMUNICATION
Group Communication
Java API to IP multicast
The Java API provides a datagram interface
to IP multicast through the class
MulticastSocket, which is a subset of
DatagramSocket with the additional
capability of being able to join multicast
groups.
The class MulticastSocket provides two
alternative constructors , allowing socket to
be creative to use either a specified local
port, or any free local port.
(Figure 18)
Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005
76
INTERPROCESS COMMUNICATION
Group Communication
import java.net.*;
import java.io.*;
public class MulticastPeer{
public static void main(String args[]){
// args give message contents and destination multicast group (e.g. "228.5.6.7")
MulticastSocket s =null;
try {
InetAddress group = InetAddress.getByName(args[1]);
s = new MulticastSocket(6789);
s.joinGroup(group);
byte [] m = args[0].getBytes();
DatagramPacket messageOut = new DatagramPacket(m, m.length, group, 6789);
s.send(messageOut);
byte[] buffer = new byte[1000];
for(int i=0; i< 3;i++) { // get messages from others in group
DatagramPacket messageIn = new DatagramPacket(buffer, buffer.length);
s.receive(messageIn);
System.out.println("Received:" + new String(messageIn.getData()));
}
s.leaveGroup(group);
}catch (SocketException e){System.out.println("Socket: " + e.getMessage());
}catch (IOException e){System.out.println("IO: " + e.getMessage());
}finally {if(s != null) s.close();}
}
Figure 18. Multicast peer joins a group and sends and receives datagrams
Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005
77
INTERPROCESS COMMUNICATION
Group Communication
A process can join a multicast group with a given
multicast address by invoking the joinGroup
method of its multicast socket.
A process can leave a specified group by invoking
the leaveGroup method of its multicast socket.
The Java API allows the TTL to be set for a
multicast socket by means of the setTimeToLive
method. The default is 1, allowing the multicast to
propagate only on the local network.
Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005
78