SlideShare a Scribd company logo
INTERPROCESS COMMUNICATION
Topics
 INTRODUCTION
 The API for the INTERNET PROTOCOLS
 EXTERNAL DATA REPRESENTATION
 CLIENT-SERVER COMMUNICATION
 GROUP COMMUNICATION
INTERPROCESS COMMUNICATION
Introduction
 Process of exchanging the data between two or more
independent process in a distributed environment is called
as Interprocess communication.
 The 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.
INTERPROCESS COMMUNICATION
Introduction
 middleware.
Figure 1. Middleware layers
Collecting data and agreement
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
 Remote Procedure Call (RPC)
 It allows a client to call a procedure in a
remote server.
INTERPROCESS COMMUNICATION
Introduction
 Request-reply protocols are designed to
support client-server communication in the
form of either RMI or RPC.
 Group multicast protocols are designed to
support group communication.
INTERPROCESS COMMUNICATION
The Characteristics of Interprocess Communication
 Synchronous and asynchronous
communication
 In the synchronous form, both send and
receive are blocking operations.
 In the asynchronous form, the use of the
send operation is non-blocking and the
receive operation can have blocking and
non-blocking variants.
SYSTEM MODEL
INTERPROCESS COMMUNICATION
The Characteristics of Interprocess Communication
 Message destinations
 A local port is a message destination
within a computer, specified as an integer.
 A port has an exactly one receiver but can
have many senders.
INTERPROCESS COMMUNICATION
The Characteristics of Interprocess Communication
 Reliability
 A reliable communication is defined in
terms of validity and integrity.
INTERPROCESS COMMUNICATION
The Characteristics of Interprocess Communication
 Ordering
 Some applications require that messages
be delivered in sender order.
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).
INTERPROCESS COMMUNICATION
Sockets
 Both forms of communication, UDP and
TCP, use the socket abstraction, which
provides and endpoint for communication
between processes.
 Interprocess communication consists of
transmitting a message between a socket
in one process and a socket in another
process.
(Figure 2)
INTERPROCESS COMMUNICATION
Sockets
Figure 2. Sockets and ports
INTERPROCESS COMMUNICATION
UDP Datagram Communication
 UDP datagram properties
 No guarantee of order preservation
 Message loss and duplications are
possible
 Necessary steps
 Creating a socket
 Binding a socket to a port and local
Internet address
 A client binds to any free local port
 A server binds to a server port
INTERPROCESS COMMUNICATION
UDP Datagram Communication
 Receive method
 It returns Internet address and port of
sender, plus message.
INTERPROCESS COMMUNICATION
UDP Datagram Communication
 Issues related to datagram
communications are:
 Message size
 IP allows for messages of up to 216 bytes.
 Any application requiring messages larger
than the maximum must fragment.
 If arriving message is too big for array
allocated to receive message content,
truncation occurs.
INTERPROCESS COMMUNICATION
UDP Datagram Communication
 Blocking
 Send: non-blocking messages
 Receive: blocking messages
 Timeout
 Receive from any
INTERPROCESS COMMUNICATION
UDP Datagram Communication
 UDP datagrams suffer from following
failures:
 Omission failure(process or channel failed)
 Messages may be dropped occasionally,
 Ordering
INTERPROCESS COMMUNICATION
Java API for UDP Datagrams
 The Java API provides datagram
communication by two classes:
 DatagramPacket
 It provides a constructor to make
an array of bytes comprising:
• Message content
• Length of message
• Internet address
• Local port number
 It provides another similar constructor for
receiving a message.
array of bytes containing message | length of message| Internet address | port number|
INTERPROCESS COMMUNICATION
Java API for UDP Datagrams
 DatagramSocket
 supports sockets for sending and receiving
UDP datagram.
 It provides a constructor with port number
as argument.
 DatagramSocket methods are:
• send and receive
• Set Timeout
• Connect
INTERPROCESS COMMUNICATION
Java API for UDP Datagrams
import java.net.*;
import java.io.*;
public class UDPClient{
public static void main(String args[]){
// args give message contents and destination hostname
try {
DatagramSocket aSocket = new DatagramSocket(); // create socket
byte [] m = args[0].getBytes();
InetAddress aHost = InetAddress.getByName(args[1]); // DNS lookup
int serverPort = 6789;
DatagramPacket request =
new DatagramPacket(m, args[0].length(), aHost, serverPort);
aSocket.send(request); //send nessage
byte[] buffer = new byte[1000];
DatagramPacket reply = new DatagramPacket(buffer, buffer.length);
aSocket.receive(reply); //wait for reply
System.out.println("Reply: " + new String(reply.getData()));
aSocket.close();
}catch (SocketException e){System.out.println("Socket: " + e.getMessage());
}catch (IOException e){System.out.println("IO: " + e.getMessage());}
} finally{if (aSocket !=null)aSocket.close()}
}
}
Figure 3. UDP client sends a message to the server and gets a reply
INTERPROCESS COMMUNICATION
Java API for UDP datagrams
import java.net.*;
import java.io.*;
public class UDPServer{
public static void main(String args[]){
DatagramSocket aSocket = null;
try {
aSocket = new DatagramSocket(6789);
byte []buffer = new byte[1000];
While(true){
DatagramPacket request =new DatagramPacket(buffer, buffer.length);
aSocket.receive(request);
DatagramPacket reply = new DatagramPacket(request.getData();
request.getLength(),request.getAddress(), request.getPort();
aSocket.send(reply);
}
}catch (SocketException e){System.out.println("Socket: " + e.getMessage());
}catch (IOException e){System.out.println("IO: " + e.getMessage());}
}finally{if (aSocket !=null)aSocket.close()}
}
}
Figure 4. UDP server repeatedly receives a request and sends it back to the client
INTERPROCESS COMMUNICATION
TCP Stream Communication
 The API to the TCP protocol provides the
abstraction of a stream of bytes to be
written to or read from.
 Characteristics of the stream abstraction:
 Message sizes
 Lost messages
 Flow control
 Message destinations
INTERPROCESS COMMUNICATION
TCP Stream Communication
 Issues related to stream communication:
 Matching of data items
 Blocking
 Threads
INTERPROCESS COMMUNICATION
TCP Stream Communication
 Use of TCP
 Many services that run over TCP
connections, with reserved port number
are:
 HTTP (Hypertext Transfer Protocol)
 FTP (File Transfer Protocol)
 Telnet
 SMTP (Simple Mail Transfer Protocol)
INTERPROCESS COMMUNICATION
TCP Stream Communication
 Java API for TCP streams
 The Java interface to TCP streams is
provided in the classes:
 ServerSocket
• It is used by a server to create a socket at
server port to listen for connect requests from
clients.
 Socket
• It is used by a pair of processes with a connection.
• The client uses a constructor to create a socket and
connect it to the remote host and port of a server.
• It provides methods for accessing input and output
streams associated with a socket.
INTERPROCESS COMMUNICATION
Java API for UDP Datagrams
Example
– The client process creates a socket, bound to the
hostname and server port 6789.
INTERPROCESS COMMUNICATION
Java API for UDP Datagrams
Example
– The server process opens a server socket to its
server port 6789 and listens for connect requests.
INTERPROCESS COMMUNICATION
TCP Stream Communication
import java.net.*;
import java.io.*;
public class TCPServer {
public static void main (String args[]) {
try{
int serverPort = 7896;
ServerSocket listenSocket = new ServerSocket(serverPort);
while(true) {
Socket clientSocket = listenSocket.accept();
Connection c = new Connection(clientSocket);
}
} catch(IOException e) {System.out.println("Listen socket:"+e.getMessage());}
}
}
Figure 6. TCP server makes a connection for each client and then echoes the client’s request
INTERPROCESS COMMUNICATION
TCP Stream Communication
class Connection extends Thread {
DataInputStream in;
DataOutputStream out;
Socket clientSocket;
public Connection (Socket aClientSocket) {
try {
clientSocket = aClientSocket;
in = new DataInputStream( clientSocket.getInputStream());
out =new DataOutputStream( clientSocket.getOutputStream());
this.start();
} catch(IOException e){System.out.println("Connection:"+e.getMessage());}
}
public void run(){
try { // an echo server
String data = in.readUTF();
out.writeUTF(data);
} catch (EOFException e){System.out.println("EOF:"+e.getMessage());
} catch (IOException e) {System.out.println("readline:"+e.getMessage());}
} finally {try{clientSocket.close();}catch(IOException e){/*close failed*/}}
}
}
Figure 7. TCP server makes a connection for each client and then echoes the client’s request
INTERPROCESS COMMUNICATION
External Data Representation
 The information stored in running programs is
represented as data structures, whereas the
information in messages consists of sequences
of bytes.
 Irrespective of the form of communication used,
the data structure must be converted to a
sequence of bytes before transmission and
rebuilt on arrival.
INTERPROCESS COMMUNICATION
External Data Representation
 External Data Representation is an agreed
standard for the representation of data
structures and primitive values.
 Data representation problems are:
 Using agreed external representation, two conversions
necessary
 Using sender’s or receiver’s format and convert at the other
end
INTERPROCESS COMMUNICATION
External Data Representation
 Marshalling
 Marshalling is the process of taking a
collection of data items and assembling
them into a form suitable for transmission
in a message.
 Unmarshalling
 Unmarshalling is the process of
disassembling a collection of data on
arrival to produce an equivalent collection
of data items at the destination.
INTERPROCESS COMMUNICATION
External Data Representation
 Three approaches to external data
representation and marshalling are:
 CORBA(Common Object Request Broker
Architecture)
 Java’s object serialization
 XML
INTERPROCESS COMMUNICATION
External Data Representation
 Marshalling and unmarshalling activities is
usually performed automatically by
middleware layer.
INTERPROCESS COMMUNICATION
CORBA Common Data Representation (CDR)
 CORBA Common Data Representation (CDR)
 CORBA CDR is the external data representation
defined with CORBA 2.0.
 It consists 15 primitive types:
 Short (16 bit)
 Long (32 bit)
 Unsigned short
 Unsigned long
 Float(32 bit)
 Double(64 bit)
 Char
 Boolean(TRUE,FALSE)
 Octet(8 bit)
 Any(can represent any basic or constructed type)
 Composite type are shown in Figure 8.
INTERPROCESS COMMUNICATION
CORBA Common Data Representation (CDR)
Figure 8. CORBA CDR for constructed types
INTERPROCESS COMMUNICATION
CORBA Common Data Representation (CDR)
 Constructed types: The primitive values that
comprise each constructed type are added
to a sequence of bytes in a particular order,
as shown in Figure 8.
INTERPROCESS COMMUNICATION
CORBA Common Data Representation (CDR)
 Figure 9 shows a message in CORBA CDR
that contains the three fields of a struct
whose respective types are string, string,
and unsigned long.
INTERPROCESS COMMUNICATION
CORBA Common Data Representation (CDR)
example: struct with value {‘Smith’, ‘London’, 1934}
Figure 9. CORBA CDR message
INTERPROCESS COMMUNICATION
Java object serialization
 In Java RMI, both object and primitive data values may
be passed as arguments and results of method
invocation.
 An object is an instance of a Java class.
 Example, the Java class equivalent to the Person struct
Public class Person implements Serializable {
Private String name;
Private String place;
Private int year;
Public Person(String aName ,String aPlace, int aYear) {
name = aName;
place = aPlace;
year = aYear;
}
//followed by methods for accessing the instance variables
}
INTERPROCESS COMMUNICATION
Java object serialization
The serialized form is illustrated in Figure 10.
Figure 10. Indication of Java serialization form
INTERPROCESS COMMUNICATION
Remote Object References
 Remote object references are needed when a
client invokes an object that is located on a
remote server.
 A remote object reference is passed in the
invocation message to specify which object is to
be invoked.
 Remote object references must be unique over
space and time.
INTERPROCESS COMMUNICATION
Remote Object References
 In general, may be many processes hosting
remote objects, so remote object referencing
must be unique among all of the processes in
the various computers in a distributed system.
 generic format for remote object references is
shown in Figure 11.
Figure 11. Representation of a remote object references
INTERPROCESS COMMUNICATION
Remote Object References
 internet address/port number: process which
created object
 time: creation time
 object number: local counter, incremented each
time an object is created in the creating process
 interface: how to access the remote object (if
object reference is passed from one client to
another)
INTERPROCESS COMMUNICATION
Client-Server Communication
 The client-server communication is designed to
support the roles and message exchanges in
typical client-server interactions.
 In the normal case, request-reply communication
is synchronous because the client process
blocks until the reply arrives from the server.
 Asynchronous request-reply communication is
an alternative that is useful where clients can
afford to retrieve replies later.
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
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.
INTERPROCESS COMMUNICATION
Client-Server Communication
 The request-reply protocol is shown in Figure 12.
Figure 12. Request-reply communication
INTERPROCESS COMMUNICATION
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.
INTERPROCESS COMMUNICATION
Client-Server Communication
Figure 13. Operations of the request-reply protocol
INTERPROCESS COMMUNICATION
Client-Server Communication
 The information to be transmitted in a request
message or a reply message is shown in Figure 14.
Figure 14. Request-reply message structure
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 forth field is an identifier for the method to be
invoked.
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.
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.
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)
INTERPROCESS COMMUNICATION
Client-Server Communication
Figure 15. RPC exchange protocols
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.
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.
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
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.
INTERPROCESS COMMUNICATION
Client-Server Communication
 A Mime type specifies a type and a
subtype, for example:
 text/plain
 text/html
 image/gif
 image/jpeg
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.
Figure 16. HTTP request message
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).
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.
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
INTERPROCESS COMMUNICATION
Client-Server Communication
 TRACE
 The server sends back the request
message
INTERPROCESS COMMUNICATION
Client-Server Communication
 A reply message specifies
 The protocol version
 A status code
 Reason
 Some headers
 An optional message body
Figure 17. HTTP reply message
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.
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.
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.
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.
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.
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.
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.
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.
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.
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
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.

More Related Content

PPTX
Distributed Systems inter process communication
PPT
Chapter 4 a interprocess communication
PPTX
Distributed Computing - API for Internet Protocols
PPTX
Inter process communication by Dr.C.R.Dhivyaa, Assistant Professor,Kongu Engi...
PPT
Interprocess Communication
PPTX
distrbuted system show how distbuted system
PDF
PDF
sockets SMTP Bmsce ppt information science and engineering
Distributed Systems inter process communication
Chapter 4 a interprocess communication
Distributed Computing - API for Internet Protocols
Inter process communication by Dr.C.R.Dhivyaa, Assistant Professor,Kongu Engi...
Interprocess Communication
distrbuted system show how distbuted system
sockets SMTP Bmsce ppt information science and engineering

Similar to Unit 2 DSDSDSDSDSDSDSDSDSDSDSDSDSDSDSDSDSDSDS.ppt (20)

PDF
28 networking
PPTX
Networking in Java
PDF
CS6601 DISTRIBUTED SYSTEMS
PPT
Md13 networking
PDF
DCS Unit-II COMMUNICATION AND COORDINATION.pdf
PPTX
Linux Inter Process Communication
PPT
Chapter 4 slides
PPTX
Advance Java-Network Programming
PPT
Network programming in Java
PPTX
5_6278455688045789623.pptx
PPT
Socket programming in C
PPTX
COMPLEXITY CHAPTER 4 LECTURE FOR FOURTH YEAR .pptx
PPTX
Socket programming
PDF
Networking
PPTX
#1 (TCPvs. UDP)
PPTX
Java socket programming
PPT
Socket Programming in Java.ppt yeh haii
PDF
Network Sockets
PDF
Sockets
28 networking
Networking in Java
CS6601 DISTRIBUTED SYSTEMS
Md13 networking
DCS Unit-II COMMUNICATION AND COORDINATION.pdf
Linux Inter Process Communication
Chapter 4 slides
Advance Java-Network Programming
Network programming in Java
5_6278455688045789623.pptx
Socket programming in C
COMPLEXITY CHAPTER 4 LECTURE FOR FOURTH YEAR .pptx
Socket programming
Networking
#1 (TCPvs. UDP)
Java socket programming
Socket Programming in Java.ppt yeh haii
Network Sockets
Sockets
Ad

Recently uploaded (20)

PPTX
CEE 2 REPORT G7.pptxbdbshjdgsgjgsjfiuhsd
PPT
Chapter 3 METAL JOINING.pptnnnnnnnnnnnnn
PPTX
mbdjdhjjodule 5-1 rhfhhfjtjjhafbrhfnfbbfnb
PDF
Launch Your Data Science Career in Kochi – 2025
PPT
Miokarditis (Inflamasi pada Otot Jantung)
PPTX
oil_refinery_comprehensive_20250804084928 (1).pptx
PDF
Introduction to Business Data Analytics.
PPTX
05. PRACTICAL GUIDE TO MICROSOFT EXCEL.pptx
PPTX
ALIMENTARY AND BILIARY CONDITIONS 3-1.pptx
PPTX
IBA_Chapter_11_Slides_Final_Accessible.pptx
PPTX
advance b rammar.pptxfdgdfgdfsgdfgsdgfdfgdfgsdfgdfgdfg
PDF
Clinical guidelines as a resource for EBP(1).pdf
PPTX
IB Computer Science - Internal Assessment.pptx
PPTX
Supervised vs unsupervised machine learning algorithms
PPTX
Introduction to Basics of Ethical Hacking and Penetration Testing -Unit No. 1...
PPTX
iec ppt-1 pptx icmr ppt on rehabilitation.pptx
PDF
Recruitment and Placement PPT.pdfbjfibjdfbjfobj
PPT
Reliability_Chapter_ presentation 1221.5784
PPTX
climate analysis of Dhaka ,Banglades.pptx
PPTX
STUDY DESIGN details- Lt Col Maksud (21).pptx
CEE 2 REPORT G7.pptxbdbshjdgsgjgsjfiuhsd
Chapter 3 METAL JOINING.pptnnnnnnnnnnnnn
mbdjdhjjodule 5-1 rhfhhfjtjjhafbrhfnfbbfnb
Launch Your Data Science Career in Kochi – 2025
Miokarditis (Inflamasi pada Otot Jantung)
oil_refinery_comprehensive_20250804084928 (1).pptx
Introduction to Business Data Analytics.
05. PRACTICAL GUIDE TO MICROSOFT EXCEL.pptx
ALIMENTARY AND BILIARY CONDITIONS 3-1.pptx
IBA_Chapter_11_Slides_Final_Accessible.pptx
advance b rammar.pptxfdgdfgdfsgdfgsdgfdfgdfgsdfgdfgdfg
Clinical guidelines as a resource for EBP(1).pdf
IB Computer Science - Internal Assessment.pptx
Supervised vs unsupervised machine learning algorithms
Introduction to Basics of Ethical Hacking and Penetration Testing -Unit No. 1...
iec ppt-1 pptx icmr ppt on rehabilitation.pptx
Recruitment and Placement PPT.pdfbjfibjdfbjfobj
Reliability_Chapter_ presentation 1221.5784
climate analysis of Dhaka ,Banglades.pptx
STUDY DESIGN details- Lt Col Maksud (21).pptx
Ad

Unit 2 DSDSDSDSDSDSDSDSDSDSDSDSDSDSDSDSDSDSDS.ppt

  • 1. INTERPROCESS COMMUNICATION Topics  INTRODUCTION  The API for the INTERNET PROTOCOLS  EXTERNAL DATA REPRESENTATION  CLIENT-SERVER COMMUNICATION  GROUP COMMUNICATION
  • 2. INTERPROCESS COMMUNICATION Introduction  Process of exchanging the data between two or more independent process in a distributed environment is called as Interprocess communication.  The 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.
  • 3. INTERPROCESS COMMUNICATION Introduction  middleware. Figure 1. Middleware layers Collecting data and agreement
  • 4. 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  Remote Procedure Call (RPC)  It allows a client to call a procedure in a remote server.
  • 5. INTERPROCESS COMMUNICATION Introduction  Request-reply protocols are designed to support client-server communication in the form of either RMI or RPC.  Group multicast protocols are designed to support group communication.
  • 6. INTERPROCESS COMMUNICATION The Characteristics of Interprocess Communication  Synchronous and asynchronous communication  In the synchronous form, both send and receive are blocking operations.  In the asynchronous form, the use of the send operation is non-blocking and the receive operation can have blocking and non-blocking variants. SYSTEM MODEL
  • 7. INTERPROCESS COMMUNICATION The Characteristics of Interprocess Communication  Message destinations  A local port is a message destination within a computer, specified as an integer.  A port has an exactly one receiver but can have many senders.
  • 8. INTERPROCESS COMMUNICATION The Characteristics of Interprocess Communication  Reliability  A reliable communication is defined in terms of validity and integrity.
  • 9. INTERPROCESS COMMUNICATION The Characteristics of Interprocess Communication  Ordering  Some applications require that messages be delivered in sender order.
  • 10. 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).
  • 11. INTERPROCESS COMMUNICATION Sockets  Both forms of communication, UDP and TCP, use the socket abstraction, which provides and endpoint for communication between processes.  Interprocess communication consists of transmitting a message between a socket in one process and a socket in another process. (Figure 2)
  • 13. INTERPROCESS COMMUNICATION UDP Datagram Communication  UDP datagram properties  No guarantee of order preservation  Message loss and duplications are possible  Necessary steps  Creating a socket  Binding a socket to a port and local Internet address  A client binds to any free local port  A server binds to a server port
  • 14. INTERPROCESS COMMUNICATION UDP Datagram Communication  Receive method  It returns Internet address and port of sender, plus message.
  • 15. INTERPROCESS COMMUNICATION UDP Datagram Communication  Issues related to datagram communications are:  Message size  IP allows for messages of up to 216 bytes.  Any application requiring messages larger than the maximum must fragment.  If arriving message is too big for array allocated to receive message content, truncation occurs.
  • 16. INTERPROCESS COMMUNICATION UDP Datagram Communication  Blocking  Send: non-blocking messages  Receive: blocking messages  Timeout  Receive from any
  • 17. INTERPROCESS COMMUNICATION UDP Datagram Communication  UDP datagrams suffer from following failures:  Omission failure(process or channel failed)  Messages may be dropped occasionally,  Ordering
  • 18. INTERPROCESS COMMUNICATION Java API for UDP Datagrams  The Java API provides datagram communication by two classes:  DatagramPacket  It provides a constructor to make an array of bytes comprising: • Message content • Length of message • Internet address • Local port number  It provides another similar constructor for receiving a message. array of bytes containing message | length of message| Internet address | port number|
  • 19. INTERPROCESS COMMUNICATION Java API for UDP Datagrams  DatagramSocket  supports sockets for sending and receiving UDP datagram.  It provides a constructor with port number as argument.  DatagramSocket methods are: • send and receive • Set Timeout • Connect
  • 20. INTERPROCESS COMMUNICATION Java API for UDP Datagrams import java.net.*; import java.io.*; public class UDPClient{ public static void main(String args[]){ // args give message contents and destination hostname try { DatagramSocket aSocket = new DatagramSocket(); // create socket byte [] m = args[0].getBytes(); InetAddress aHost = InetAddress.getByName(args[1]); // DNS lookup int serverPort = 6789; DatagramPacket request = new DatagramPacket(m, args[0].length(), aHost, serverPort); aSocket.send(request); //send nessage byte[] buffer = new byte[1000]; DatagramPacket reply = new DatagramPacket(buffer, buffer.length); aSocket.receive(reply); //wait for reply System.out.println("Reply: " + new String(reply.getData())); aSocket.close(); }catch (SocketException e){System.out.println("Socket: " + e.getMessage()); }catch (IOException e){System.out.println("IO: " + e.getMessage());} } finally{if (aSocket !=null)aSocket.close()} } } Figure 3. UDP client sends a message to the server and gets a reply
  • 21. INTERPROCESS COMMUNICATION Java API for UDP datagrams import java.net.*; import java.io.*; public class UDPServer{ public static void main(String args[]){ DatagramSocket aSocket = null; try { aSocket = new DatagramSocket(6789); byte []buffer = new byte[1000]; While(true){ DatagramPacket request =new DatagramPacket(buffer, buffer.length); aSocket.receive(request); DatagramPacket reply = new DatagramPacket(request.getData(); request.getLength(),request.getAddress(), request.getPort(); aSocket.send(reply); } }catch (SocketException e){System.out.println("Socket: " + e.getMessage()); }catch (IOException e){System.out.println("IO: " + e.getMessage());} }finally{if (aSocket !=null)aSocket.close()} } } Figure 4. UDP server repeatedly receives a request and sends it back to the client
  • 22. INTERPROCESS COMMUNICATION TCP Stream Communication  The API to the TCP protocol provides the abstraction of a stream of bytes to be written to or read from.  Characteristics of the stream abstraction:  Message sizes  Lost messages  Flow control  Message destinations
  • 23. INTERPROCESS COMMUNICATION TCP Stream Communication  Issues related to stream communication:  Matching of data items  Blocking  Threads
  • 24. INTERPROCESS COMMUNICATION TCP Stream Communication  Use of TCP  Many services that run over TCP connections, with reserved port number are:  HTTP (Hypertext Transfer Protocol)  FTP (File Transfer Protocol)  Telnet  SMTP (Simple Mail Transfer Protocol)
  • 25. INTERPROCESS COMMUNICATION TCP Stream Communication  Java API for TCP streams  The Java interface to TCP streams is provided in the classes:  ServerSocket • It is used by a server to create a socket at server port to listen for connect requests from clients.  Socket • It is used by a pair of processes with a connection. • The client uses a constructor to create a socket and connect it to the remote host and port of a server. • It provides methods for accessing input and output streams associated with a socket.
  • 26. INTERPROCESS COMMUNICATION Java API for UDP Datagrams Example – The client process creates a socket, bound to the hostname and server port 6789.
  • 27. INTERPROCESS COMMUNICATION Java API for UDP Datagrams Example – The server process opens a server socket to its server port 6789 and listens for connect requests.
  • 28. INTERPROCESS COMMUNICATION TCP Stream Communication import java.net.*; import java.io.*; public class TCPServer { public static void main (String args[]) { try{ int serverPort = 7896; ServerSocket listenSocket = new ServerSocket(serverPort); while(true) { Socket clientSocket = listenSocket.accept(); Connection c = new Connection(clientSocket); } } catch(IOException e) {System.out.println("Listen socket:"+e.getMessage());} } } Figure 6. TCP server makes a connection for each client and then echoes the client’s request
  • 29. INTERPROCESS COMMUNICATION TCP Stream Communication class Connection extends Thread { DataInputStream in; DataOutputStream out; Socket clientSocket; public Connection (Socket aClientSocket) { try { clientSocket = aClientSocket; in = new DataInputStream( clientSocket.getInputStream()); out =new DataOutputStream( clientSocket.getOutputStream()); this.start(); } catch(IOException e){System.out.println("Connection:"+e.getMessage());} } public void run(){ try { // an echo server String data = in.readUTF(); out.writeUTF(data); } catch (EOFException e){System.out.println("EOF:"+e.getMessage()); } catch (IOException e) {System.out.println("readline:"+e.getMessage());} } finally {try{clientSocket.close();}catch(IOException e){/*close failed*/}} } } Figure 7. TCP server makes a connection for each client and then echoes the client’s request
  • 30. INTERPROCESS COMMUNICATION External Data Representation  The information stored in running programs is represented as data structures, whereas the information in messages consists of sequences of bytes.  Irrespective of the form of communication used, the data structure must be converted to a sequence of bytes before transmission and rebuilt on arrival.
  • 31. INTERPROCESS COMMUNICATION External Data Representation  External Data Representation is an agreed standard for the representation of data structures and primitive values.  Data representation problems are:  Using agreed external representation, two conversions necessary  Using sender’s or receiver’s format and convert at the other end
  • 32. INTERPROCESS COMMUNICATION External Data Representation  Marshalling  Marshalling is the process of taking a collection of data items and assembling them into a form suitable for transmission in a message.  Unmarshalling  Unmarshalling is the process of disassembling a collection of data on arrival to produce an equivalent collection of data items at the destination.
  • 33. INTERPROCESS COMMUNICATION External Data Representation  Three approaches to external data representation and marshalling are:  CORBA(Common Object Request Broker Architecture)  Java’s object serialization  XML
  • 34. INTERPROCESS COMMUNICATION External Data Representation  Marshalling and unmarshalling activities is usually performed automatically by middleware layer.
  • 35. INTERPROCESS COMMUNICATION CORBA Common Data Representation (CDR)  CORBA Common Data Representation (CDR)  CORBA CDR is the external data representation defined with CORBA 2.0.  It consists 15 primitive types:  Short (16 bit)  Long (32 bit)  Unsigned short  Unsigned long  Float(32 bit)  Double(64 bit)  Char  Boolean(TRUE,FALSE)  Octet(8 bit)  Any(can represent any basic or constructed type)  Composite type are shown in Figure 8.
  • 36. INTERPROCESS COMMUNICATION CORBA Common Data Representation (CDR) Figure 8. CORBA CDR for constructed types
  • 37. INTERPROCESS COMMUNICATION CORBA Common Data Representation (CDR)  Constructed types: The primitive values that comprise each constructed type are added to a sequence of bytes in a particular order, as shown in Figure 8.
  • 38. INTERPROCESS COMMUNICATION CORBA Common Data Representation (CDR)  Figure 9 shows a message in CORBA CDR that contains the three fields of a struct whose respective types are string, string, and unsigned long.
  • 39. INTERPROCESS COMMUNICATION CORBA Common Data Representation (CDR) example: struct with value {‘Smith’, ‘London’, 1934} Figure 9. CORBA CDR message
  • 40. INTERPROCESS COMMUNICATION Java object serialization  In Java RMI, both object and primitive data values may be passed as arguments and results of method invocation.  An object is an instance of a Java class.  Example, the Java class equivalent to the Person struct Public class Person implements Serializable { Private String name; Private String place; Private int year; Public Person(String aName ,String aPlace, int aYear) { name = aName; place = aPlace; year = aYear; } //followed by methods for accessing the instance variables }
  • 41. INTERPROCESS COMMUNICATION Java object serialization The serialized form is illustrated in Figure 10. Figure 10. Indication of Java serialization form
  • 42. INTERPROCESS COMMUNICATION Remote Object References  Remote object references are needed when a client invokes an object that is located on a remote server.  A remote object reference is passed in the invocation message to specify which object is to be invoked.  Remote object references must be unique over space and time.
  • 43. INTERPROCESS COMMUNICATION Remote Object References  In general, may be many processes hosting remote objects, so remote object referencing must be unique among all of the processes in the various computers in a distributed system.  generic format for remote object references is shown in Figure 11. Figure 11. Representation of a remote object references
  • 44. INTERPROCESS COMMUNICATION Remote Object References  internet address/port number: process which created object  time: creation time  object number: local counter, incremented each time an object is created in the creating process  interface: how to access the remote object (if object reference is passed from one client to another)
  • 45. INTERPROCESS COMMUNICATION Client-Server Communication  The client-server communication is designed to support the roles and message exchanges in typical client-server interactions.  In the normal case, request-reply communication is synchronous because the client process blocks until the reply arrives from the server.  Asynchronous request-reply communication is an alternative that is useful where clients can afford to retrieve replies later.
  • 46. 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
  • 47. 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.
  • 48. INTERPROCESS COMMUNICATION Client-Server Communication  The request-reply protocol is shown in Figure 12. Figure 12. Request-reply communication
  • 49. INTERPROCESS COMMUNICATION 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.
  • 50. INTERPROCESS COMMUNICATION Client-Server Communication Figure 13. Operations of the request-reply protocol
  • 51. INTERPROCESS COMMUNICATION Client-Server Communication  The information to be transmitted in a request message or a reply message is shown in Figure 14. Figure 14. Request-reply message structure
  • 52. 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 forth field is an identifier for the method to be invoked.
  • 53. 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.
  • 54. 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.
  • 55. 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)
  • 57. 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.
  • 58. 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.
  • 59. 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
  • 60. 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.
  • 61. INTERPROCESS COMMUNICATION Client-Server Communication  A Mime type specifies a type and a subtype, for example:  text/plain  text/html  image/gif  image/jpeg
  • 62. 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. Figure 16. HTTP request message
  • 63. 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).
  • 64. 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.
  • 65. 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
  • 66. INTERPROCESS COMMUNICATION Client-Server Communication  TRACE  The server sends back the request message
  • 67. INTERPROCESS COMMUNICATION Client-Server Communication  A reply message specifies  The protocol version  A status code  Reason  Some headers  An optional message body Figure 17. HTTP reply message
  • 68. 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.
  • 69. 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.
  • 70. 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.
  • 71. 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.
  • 72. 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.
  • 73. 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.
  • 74. 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.
  • 75. 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.
  • 76. 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.
  • 77. 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
  • 78. 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.