2 Distributed Computing – Course
outcome
Know about the distributed objects and protocols
1/6/2026
3 MODULE 2 :Inter process
Communications
Interprocess communication (IPC) in a distributed
system is the mechanism that allows processes on
different, networked computers to exchange data and
coordinate their activities.
1/6/2026
4 MODULE 2 :Inter process
Communications
The API for internet protocols
External data representation and marshalling
Multicast communication
Issues in the design of IPC
1/6/2026
5 Middle layers
1/6/2026
6 Message passing (IPC)
Message passing between a pair of processes can be
supported by two message communication operations,
send and receive, defined in terms of destinations and
messages.
To communicate, one process sends a message (a
sequence of bytes) to a destination and another process
at the destination receives the message.
Inter process communication consists of transmitting a
message between a socket in one process and a socket
in another process.
1/6/2026
7 Synchronous communication
A queue is associated with each message destination.
Sending processes cause messages to be added to remote
queues and receiving processes remove messages from
local queues. Communication between the sending and
receiving processes may be either synchronous or
asynchronous.
In the synchronous form of communication, the sending and
receiving processes synchronize at every message.
In this case, both send and receive are blocking operations.
Whenever a send is issued the sending process (or thread) is
blocked until the corresponding receive is issued.
Whenever a receive is issued by a process (or thread), it
blocks until a message arrives.
1/6/2026
8 Synchronous Communication
In sync communication, the sender and receiver must wait for each
other.
It’s like having a live phone call—both need to talk and listen at the
same time.
Sender blocks (waits):
When the sender sends a message, it waits until the receiver
confirms that the message is received.
Receiver blocks:
The receiver waits until it gets a message from the sender before
continuing.
Synchronous Example:
You call your friend, and they pick up.
You talk only after they respond (both wait for each other).
1/6/2026
9 Asynchronous communication
The use of the send operation is non-blocking in that the
sending process is allowed to proceed as soon as the
message has been copied to a local buffer, and the
transmission of the message proceeds in parallel with
the sending process.
The receive operation can have blocking and non-
blocking variants.
In the non-blocking variant, the receiving process
proceeds with its program after issuing a receive
operation, which provides a buffer to be filled in the
background, but it must separately receive notification
that its buffer has been filled, by polling or interrupt.
1/6/2026
10 Asynchronous communication
In asynchronous communication, the sender sends the
message and immediately moves on, without waiting for
the receiver.
It’s like sending a text message—after you send it, you
don’t wait; the receiver will read it when they’re ready.
Sender doesn’t block:
The sender sends the message and immediately
continues its work.
Receiver doesn’t block:
The receiver picks up the message whenever it’s ready.
Example : You send a text to your friend.
They read and reply when they’re free (no waiting).
1/6/2026
11 Networking Basics
Whenever any application in one computer sends data
to another application of a different computer then it
sends using IP Address and MAC Address.
Computer data is first received using their IP or MAC
address then it is delivered to the application whose port
number is with the data packets.
For instance, imagine your MAC Address or IP Address
as the PIN code of the nearest Post Office and your
house address as a Port.
Port is a logical address of a 16-bit unsigned integer that
is allotted to every application on the computer that
uses the internet to send or receive data 1/6/2026
12 Networking Ports
Every time any application sends any data, it is identified by the
port that which the application sent that data and the data is to be
transferred to the receiver application according to its port.
In the OSI Model ports are used in the Transport layer. Ports are
assigned by computer i.e. operating system to different
applications.
Ports help computer to differentiate between incoming and
outgoing traffic.
Since the port is a 16-bit unsigned number it ranges from 0 to 65535.
1/6/2026
13 Socket and Ports
Both forms of communication (UDP and TCP) use the socket
abstraction, which provides an endpoint for communication
between processes.
agreed port
any port
socket socket
message
client server
other ports
Internet address = [Link] Internet address = [Link]
[Link].K 1/6/2026
14 Socket and Ports
For a process to receive messages, its socket must be bound to a
local port and one of the Internet addresses of the computer on
which it runs.
Messages sent to a particular Internet address and port number can
be received only by a process whose socket is associated with that
Internet address and port number.
Processes may use the same socket for sending and receiving
messages.
Any number of processes may send messages to the same port.
Each socket is associated with a particular protocol – either UDP or
TCP
[Link].K 1/6/2026
15 API for IP protocols
Java API for Internet addresses , As the IP packets
underlying UDP and TCP are sent to Internet addresses,
Java provides a class, InetAddress, that represents
Internet addresses.
In Java, APIs related to Internet addresses allow
developers to work with IP addresses, hostnames, and
domain names.
key classes and libraries for managing Internet
addresses are primarily part of the [Link] package
[Link].K 1/6/2026
16 Networking Basics –UDP
User Datagram Protocol
Transport layer protocol
Connection less protocol.
Unreliable
Limited error checking
Good for small messages
Supports broadcast
[Link].K 1/6/2026
17 UDP -IPC
Definition: The User Datagram Protocol (UDP) is a
lightweight, connectionless transport layer protocol.
Purpose: Allows applications to send messages, called
datagrams, with minimal overhead.
Key Characteristics:
No connection setup (unlike TCP).
Provides basic message-oriented data transmission.
[Link].K 1/6/2026
18 Communication using UDP
Run the Server:
Start the UDPServer first. It will wait for incoming messages.
Run the Client:
Start the UDPClient. It will send the message "Hello, Server!" to the server.
Server Response:
The server receives the message and prints it out.
Then, it sends back a response message
("Hello, Client! Message received.") to the client.
Client Receives Response:
The client receives the response from the server and prints it out.
[Link].K 1/6/2026
19 Networking Basics of TCP
Transmission Control Protocol.
Transport layer protocol
Connection oriented protocol.
It establishes the connection prior to the data transfer across the
devices.
Reliable
Flow control
Full duplex
Stream oriented.
[Link].K 1/6/2026
20 Java package - Socket
Socket : one end-point of a two-way communication link between
two programs running on the network.
Endpoint : IP address plus port number - Every TCP connection
unique two endpoints multiple connections
[Link].K 1/6/2026
21 Java package - Socket
Socket : Socket : endpoint for communications between the hosts.
[Link].K 1/6/2026
22 Java package - Socket
ServerSocket : used to create a server socket and establish
communication with clients
[Link].K 1/6/2026
23 Demo1 for Client Server application (Server
code)
import [Link].*;
import [Link].*;
public class ServerChat {
public static void main(String[] args) throws IOException {
ServerSocket serverSocket = new ServerSocket(12345);
[Link]("Server started, waiting for client...");
Socket clientSocket = [Link]();
[Link]("Client connected: " + [Link]());
BufferedReader in = new BufferedReader(new
InputStreamReader([Link]()));
PrintWriter out = new PrintWriter([Link](), true);
String message = [Link]();
[Link]("Received from client: " + message);
[Link]("Server: Message received - " + message);
[Link]();
[Link]();
[Link]("Server closed.");
}
}
[Link].K 1/6/2026
24 Demo1 for Client Server application (Client
code)
import [Link].*;
import [Link].*;
import [Link];
public class ClientChat {
public static void main(String[] args) throws IOException {
Socket socket = new Socket("localhost", 12345);
[Link]("Connected to server.");
PrintWriter out = new PrintWriter([Link](), true);
BufferedReader in = new BufferedReader(new InputStreamReader([Link]()));
Scanner scanner = new Scanner([Link]);
[Link]("Enter message to send to server: ");
String message = [Link]();
[Link](message);
String response = [Link]();
[Link]("Received from server: " + response);
[Link]();
[Link]();
[Link]("Client closed.");
[Link].K 1/6/2026
25 Demo1 for Client Server application output
[Link].K 1/6/2026
26 Demo2 for Client Server application (Server
code)
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class EchoReverseServer {
public static void main(String[] args)
{ int port = 6868;
try (ServerSocket echoServerSocket = new ServerSocket(port))
{
[Link]("Server is listening on port number " + port);
[Link].K 1/6/2026
27 Demo2 for Client Server application (Server
code)
while (true) {
try (Socket serverSocketObject = [Link]())
{ [Link]("New client have connected");
InputStream input = [Link]();
BufferedReader reader = new BufferedReader(new InputStreamReader(input));
OutputStream output = [Link]();
PrintWriter writer = new PrintWriter(output, true);
String text;
do {
text = [Link]();
String reversedStr = new StringBuilder(text).reverse().toString();
[Link]("Server replied: " + reversedStr);
} while ();
}
}
}
catch (IOException ex) {
[Link]("Server Exception: " + [Link]());
}}}
[Link].K 1/6/2026
28 Demo2 for Client Server application (Client code)
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class EchoReverseClient {
public static void main(String[] args) {
String hostname = "localhost";
int port = 6868;
try (Socket socket = new Socket(hostname, port))
{
OutputStream output = [Link]();
[Link].K 1/6/2026
29 Demo2 for Client Server application (Client code)
PrintWriter writer = new PrintWriter(output, true);
BufferedReader br = new BufferedReader(new InputStreamReader([Link]));
String text;
do {
[Link]("Enter the text(Client Side): ");
text = [Link]();
[Link](text);
InputStream input = [Link]();
BufferedReader reader = new BufferedReader(new InputStreamReader(input));
String strFromServer = [Link]();
[Link](strFromServer);
} while ();
[Link]();
} catch (UnknownHostException ex) {
[Link]("Server not found: " + [Link]());
} catch (IOException ex) {
[Link]("I/O error: " + [Link]());
}}}
[Link].K 1/6/2026
30 Demo2 for Client Server application
Output
[Link].K 1/6/2026
31 UDP - DatagramSocket Class
Connection-less socket - sending and receiving datagram network
Constructors in DatagramSocket class
[Link].K 1/6/2026
32 UDP - DatagramPacket Class
Message – send – receive – data container
No order – no guarantee on the data / packet delivery
Constructors in DatagramPacket class
[Link].K 1/6/2026
33 Demo for Client Server application
using UDP (Server code)
import [Link];
import [Link];
import [Link];
public class UDPServer {
public static void main(String[] args) {
try {
DatagramSocket serverSocket = new DatagramSocket(9876);
byte[] receiveData = new byte[1024];
while (true) {
DatagramPacket receivePacket = new DatagramPacket(receiveData,
[Link]);
[Link](receivePacket);
String message = new String([Link](), 0,
[Link]());
[Link]("Received: " + message);
[Link].K 1/6/2026
34 Demo for Client Server application
using UDP (Server code)
InetAddress IPAddress = [Link]();
int port = [Link]();
String response = "Server says: " + [Link]();
byte[] sendData = [Link]();
DatagramPacket sendPacket = new DatagramPacket(sendData,
[Link], IPAddress, port);
[Link](sendPacket);
}
} catch (Exception e) {
[Link]();
}
}
}
[Link].K 1/6/2026
35 Demo for Client Server application
using UDP (Client code)
import [Link];
import [Link];
import [Link];
import [Link];
public class UDPClient {
public static void main(String[] args) throws Exception {
DatagramSocket socket = new DatagramSocket();
InetAddress serverAddress = [Link]("localhost");
Scanner scanner = new Scanner([Link]);
while (true) {
[Link]("Enter message (type 'exit' to quit): ");
String message = [Link]();
byte[] sendData = [Link]();
DatagramPacket sendPacket = new DatagramPacket(sendData, [Link],
serverAddress, 9876);
[Link](sendPacket);
[Link].K 1/6/2026
36 Demo for Client Server application
using UDP (Client code)
if ([Link]().equalsIgnoreCase("exit")) {
[Link]("Client exiting...");
break;
}
byte[] receiveData = new byte[1024];
DatagramPacket receivePacket = new DatagramPacket(receiveData,
[Link]);
[Link](receivePacket);
String responseMessage = new String([Link](), 0,
[Link]());
[Link]("Received from server: " + responseMessage);
}
[Link]();
[Link]();
}
};
[Link].K 1/6/2026
37 Demo for Client Server application
using UDP (Output)
[Link].K 1/6/2026
38 Sockets used for datagrams
[Link].K 1/6/2026
39 Sockets used for Streams
[Link].K 1/6/2026
40 Client Server chat application using
TCP
// Server (TCP)
ServerSocket serverSocket = new ServerSocket(port);
Socket clientSocket = [Link](); // Blocking call, waits for
a client
BufferedReader in = new BufferedReader(new
InputStreamReader([Link]()));
PrintWriter out = new PrintWriter([Link](), true);
// Client (TCP)
Socket socket = new Socket(hostName, port);
PrintWriter out = new PrintWriter([Link](), true);
BufferedReader in = new BufferedReader(new
InputStreamReader([Link]()));
[Link].K 1/6/2026
41 Client Server chat application using
UDP
Connectionless: UDP does not establish a connection. It sends data
packets (datagrams) independently, without guarantee of delivery or
order.
Datagram Sockets: Uses DatagramSocket for both client and server.
Datagram Packets: Data is sent and received in packets using
DatagramPacket. Methods:
[Link](DatagramPacket): Receives a datagram.
[Link](DatagramPacket): Sends a datagram.
[Link].K 1/6/2026
42 External Data Representation and Marshalling
In distributed systems, especially in the context of
communication between different processes, External
Data Representation (XDR) and marshalling are crucial
concepts for ensuring that data is properly formatted
and transferred across network boundaries.
External Data Representation is a standard way of
encoding data structures so that they can be transmitted
between different machines with varying architectures.
XDR provides a method for serializing data so that it can
be understood regardless of the hardware or software
platform.
[Link].K 1/6/2026
43 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 structures
must be flattened (converted to a sequence of bytes) before
transmission and rebuilt on arrival.
To enable any two computers to exchange binary data values:
The values are converted to an agreed external format before
transmission and converted to the local form on receipt
If the two computers are known to be the same type, the conversion
to external format can be omitted.
[Link].K 1/6/2026
44 External Data Representation
The values are transmitted in the sender’s format, together with an
indication of the format used, and the recipient converts the values
if necessary.
To support RMI or RPC, any data type that can be passed as an
argument or returned as a result must be able to be flattened and
the individual primitive data values represented in an agreed
format.
An agreed standard for the representation of data structures and
primitive values is called an external data representation.
[Link].K 1/6/2026
45 Key Features of XDR:
Machine Independence: XDR ensures that data structures are
encoded in a format that is independent of the architecture (e.g.,
byte order, size of data types) of the machines involved.
Standardized Format: It defines how various data types (integers,
floating-point numbers, arrays, structures) should be represented in
a consistent way.
Interoperability: XDR allows different systems (e.g., those running
different operating systems or hardware) to communicate by
agreeing on a common data format.
Serialization is the process of converting an object's state (data and
structure) into a format that can be:
Stored (e.g., in a file or database).
Transmitted (e.g., over a network to another system). 1/6/2026
[Link].K
46 Need for Serialization
Serialization is used
Saving Data: Storing objects in files or databases for later
use.
Network Communication: Sending objects between
applications, such as in Remote Method Invocation
(RMI).
Caching: Persisting data temporarily for quick reuse.
[Link].K 1/6/2026
47 Examples of XDR Representation:
Integer Representation: An integer might be represented
in 4 bytes using a specific byte order (big-endian).
String Representation: Strings are typically preceded by
a length field to indicate how many bytes follow.
[Link].K 1/6/2026
48 Mashalling
Definition: Marshalling is the process of converting an in-memory
data structure into a format suitable for transmission or storage. This
often involves serializing the data into a byte stream or a specific
format (like XDR) that can be easily sent over a network or saved to
a file.
Key Steps in Marshalling:
Serialization: The data structure is converted into a linear sequence
of bytes. This includes converting complex data types (like objects
or arrays) into a flat format.
Data Encoding: The serialized data is encoded using a specified
representation format (e.g., XDR) to ensure it can be correctly
interpreted by the receiver.
Transmission or Storage: The marshalled data is sent over a network
or saved to a file.
[Link].K 1/6/2026
49 Unmarshalling
Definition: Unmarshalling is the reverse process of marshalling. It
involves converting a byte stream back into the original data
structure or object.
This is essential for the receiving process to correctly interpret the
data sent by the sender.
Key Steps in Unmarshalling:
Decoding: The byte stream is read and decoded according to the
agreed format (e.g., XDR).
Deserialization: The decoded data is transformed back into its
original in-memory representation, reconstructing the data structure
from the byte stream.
[Link].K 1/6/2026
50 Alternative approaches to XDR and
marshalling
Three alternative approaches to external data representation and
marshalling
CORBA’s common data representation (CDR)
Java’s object serialization
XML (Extensible Markup Language)
[Link].K 1/6/2026
51 CDR (CORBA)
CDR provides a universal format for encoding data types
to ensure interoperability between heterogeneous
systems.
Data Representation:
CDR defines a binary encoding for basic data types
(e.g., integers, floats, characters) and composite types
(e.g., structs, sequences).
It relies on a canonical format to avoid ambiguities
across platforms with differing architectures (e.g., little-
endian vs. big-endian).
[Link].K 1/6/2026
52 CDR (CORBA)
Example
Big-endian stores the most significant byte (MSB) first (e.g.,
0x12345678 as 12 34 56 78), like we write numbers; little-endian
stores the least significant byte (LSB) first (e.g., 0x12345678 as 78 56
34 12)
For the number 0x44332211, big-endian puts 44 at the lowest
address, while little-endian puts 11 at the lowest address, making it
11 22 33 44.
[Link].K 1/6/2026
53 Encoding Rules
Primitive Types:
Integers: Represented in a fixed-size, big-endian format (e.g., 16-bit,
32-bit).
Floating-point numbers: Encoded according to the IEEE 754
standard.
Characters: Encoded as single bytes for ASCII; multi-byte encoding
for wide characters.
Booleans: Stored as a single byte (0 = false, 1 = true).
[Link].K 1/6/2026
54 Encoding Rules
Complex Types:
Strings: Encoded as a 32-bit integer specifying the string length,
followed by the characters and a null terminator.
Structures: Fields are serialized sequentially, with alignment rules
applied to ensure proper boundaries.
Arrays: Elements are serialized in row-major order.
Sequences: Consist of a length field followed by the serialized
elements.
[Link].K 1/6/2026
55 Encoding Rules
Complex Types:
Strings:
An example of the string "Hello" encoded with a 32-bit (4-byte)
length prefix, followed by the character data and a null terminator,
is represented below
[Link].K 1/6/2026
56 Encoding Rules
Complex Types:
Structures: Fields are serialized sequentially, with alignment rules
applied to ensure proper boundaries.
The total size of the structure in memory is 8 bytes (1 + 1 (padding) + 2 + 4)
[Link].K 1/6/2026
57 Encoding Rules
Complex Types:
Arrays: Elements are serialized in row-major order.
In row-major order, the elements of a multidimensional array are stored in
linear memory sequentially row by row. The entire first row is placed in
memory, followed by the entire second row, and so on.
Consider a 2-dimensional array (2 rows, 3 columns) named A with the
following logical structure:
A = \begin{bmatrix} 1 & 2 & 3 \ 4 & 5 & 6 \end{bmatrix}
Here, A[0][0] is 1, A[0][1] is 2, and so on.
[Link].K 1/6/2026
58 Encoding Rules
Complex Types:
Sequences: Consist of a length field followed by the serialized
elements.
Example: Serializing a Sequence of Integers
Consider a simple list (sequence) of three 16-bit integers: [300, 5,
255]
[Link].K 1/6/2026
59 Encoding Rules
[Link].K 1/6/2026
60 CORBA CDR for constructed types
[Link].K 1/6/2026
61 CORBA CDR message
[Link].K 1/6/2026
62 Java serialized form
[Link].K 1/6/2026
63 XML (Extensible Markup Language)
Person structure
[Link].K 1/6/2026
64 An XML schema for the Person structure
Person structure
[Link].K 1/6/2026
65 Multicast Communication
Multicast Communication: This involves the transmission of information
from one sender to multiple receivers, efficiently. It differs from unicast
(one-to-one) and broadcast (one-to-all) communication.
Key Concepts:
Multicast Group:
A set of receivers that are interested in receiving a particular data
stream. Each multicast group is identified by a unique multicast
address.
Membership Management:
The process of managing the membership of a multicast group.
Receivers can join or leave a group dynamically, and the system keeps
track of the current members.
Multicast Routing:
The technique of routing multicast packets from the sender to the
multicast group. This involves creating a multicast distribution tree to
efficiently deliver packets to all members of the group.
[Link].K 1/6/2026
66 Multicast Communication-Functionality
Group Membership: Nodes join a specific multicast group (often
using Class D IP addresses).
Single Send: The sender sends the data once, and routers replicate
the packets only as needed along paths to group members.
Protocols: Relies on protocols like IGMP (Internet Group
Management Protocol) for group management and multicast
routing.
Transport: Often uses UDP for speed but can implement reliable
multicast protocols (like reliable UDP) for guaranteed delivery.
[Link].K 1/6/2026
67 Multicast Communication-Key
Characteristics
Efficiency: Reduces network traffic and server load
compared to sending individual messages to each
recipient.
Scalability: Handles large numbers of recipients
effectively, crucial for content distribution.
Fault Tolerance: Can improve resilience by distributing
data across nodes.
[Link].K 1/6/2026
68 Reliable Multicast
FIFO (First-In, First-Out): Messages arrive in the order they
were sent by the source.
Causal Ordering: Preserves cause-and-effect
relationships between messages (if A causes B, B arrives
after A).
Total Ordering (Atomic Multicast): All nodes receive
messages in the exact same global order, ensuring
consistency for shared state.
[Link].K 1/6/2026
69 Multicast Protocols:
Several protocols are used to implement multicast
communication:
Internet Group Management Protocol (IGMP): Manages
group membership in a local network.
Protocol Independent Multicast (PIM): Provides routing
for multicast traffic across networks.
Multicast Extensions to OSPF (MOSPF): An extension of
OSPF for multicast routing.
[Link].K 1/6/2026
70 Multicast Communication - Applications
Multicast communication is widely used in:
Live Streaming/Video Conferencing: Distributing video to
many viewers simultaneously.
Financial Services: Pushing real-time stock quotes to
trading platforms.
Software Updates: Distributing patches to millions of
devices efficiently.
Online Gaming: Synchronizing game state among
players.
Distributed Databases: Replicating data updates to
multiple database instances.
[Link].K 1/6/2026
71 Challenges in the design of IPC
IPC implementation involves several technical challenges that
require careful consideration.
Synchronization
It represents a fundamental challenge in ensuring processes access
shared resources without conflicts.
Race conditions occur when multiple processes attempt to modify
shared data simultaneously, potentially causing data corruption or
system instability.
Data Consistency
It requires maintaining data integrity when information is shared or
exchanged between processes.
Without proper coordination, processes might read partially
updated data or overwrite each other’s changes.
[Link].K 1/6/2026
72 Challenges in the design of IPC
Deadlock
It creates situations where two or more processes are blocked
indefinitely, waiting for each other to release resources.
Preventing deadlock requires careful resource allocation strategies
and timeout mechanisms.
Overhead
It introduces performance costs through communication and
synchronization mechanisms.
System calls, data copying, and context switches all consume CPU
cycles and can impact overall system performance.
[Link].K 1/6/2026
73 Challenges in the design of IPC
Security
It involves protecting communication channels from unauthorized
access or tampering.
IPC mechanisms must implement appropriate access controls and,
in some cases, encryption to maintain data confidentiality and
integrity.
[Link].K 1/6/2026