DS Unit Iii
DS Unit Iii
Inter Process Communication: Introduction, The API for the internet protocols, External Data
Representation and Marshalling, Client-Server Communication, Group Communication, Case Study:
IPC in UNIX.
Distributed Objects and Remote Invocation: Introduction, Communication between Distributed
Objects, Remote Procedure Call, Events and Notifications, Case study-Java RMI.
Definition
"Inter-process communication is used for exchanging useful information between numerous threads in one or more
processes (or programs)."
To understand inter process communication, you can consider the following given diagram that illustrates the importance of
inter-process communication:
We will now discuss some different approaches to inter-process communication which are as follows:
These are a few different approaches for Inter- Process Communication:
1. Pipes
2. Shared Memory
3. Message Queue
4. Direct Communication
5. Indirect communication
6. Message Passing
7. FIFO
Pipe:-
The pipe is a type of data channel that is unidirectional in nature. It means that the data in this type of data channel can be
moved in only a single direction at a time. Still, one can use two-channel of this type, so that he can able to send and receive
data in two processes. Typically, it uses the standard methods for input and output. These pipes are used in all types of
POSIX systems and in different versions of window operating systems as well.
Shared Memory:-
It can be referred to as a type of memory that can be used or accessed by multiple processes simultaneously. It is primarily
used so that the processes can communicate with each other. Therefore the shared memory is used by almost all POSIX and
Windows operating systems as well.
Message Queue:-
In general, several different messages are allowed to read and write the data to the message queue. In the message queue,
the messages are stored or stay in the queue unless their recipients retrieve them. In short, we can also say that the message
queue is very helpful in inter-process communication and used by all operating systems.
To understand the concept of Message queue and Shared memory in more detail, let's take a look at its diagram given
below:
Message Passing:-
It is a type of mechanism that allows processes to synchronize and communicate with each other. However, by using the
message passing, the processes can communicate with each other without restoring the hared variables.
Usually, the inter-process communication mechanism provides two operations that are as follows:
o send (message)
o received (message)
Direct Communication:-
In this type of communication process, usually, a link is created or established between two communicating processes.
However, in every pair of communicating processes, only one link can exist.
Indirect Communication
Indirect communication can only exist or be established when processes share a common mailbox, and each pair of these
processes shares multiple communication links. These shared links can be unidirectional or bi-directional.
FIFO:-
It is a type of general communication between two unrelated processes. It can also be considered as full-duplex, which
means that one process can communicate with another process and vice versa.
1. Communication Channels: IPC relies on various communication channels to facilitate data exchange between processes.
These channels can be shared memory, pipes, sockets, message queues, or even remote procedure calls (RPC).
2. Synchronization: IPC allows processes to synchronize their actions and coordinate their activities. This ensures that
processes can work together effectively and avoid conflicts when accessing shared resources.
3. Message Passing: One of the key mechanisms in IPC is message passing, where processes send and receive messages to
communicate with each other. Messages can contain data, instructions, or requests, and they are typically sent through
predefined communication channels.
4. Addressing: To establish communication between processes, each process involved in IPC needs to have a unique
identifier or address. This allows processes to send messages to specific destinations and receive messages from specific
sources.
5. Blocking vs. Non-blocking: IPC can be implemented in different ways, including blocking and non-blocking mechanisms. In
a blocking IPC, the sender process is blocked until the receiver process acknowledges the message. In contrast, non-blocking
IPC allows the sender to continue its execution without waiting for a response.
6. Error Handling: IPC mechanisms often provide error handling capabilities to deal with exceptional situations. This includes
handling message failures, timeouts, or other error conditions that may occur during the communication process.
7. Scalability: IPC should be designed to handle a large number of processes efficiently. Scalability is crucial to ensure that
the system can handle increased workloads and maintain performance even with a growing number of processes.
8. Security: IPC mechanisms should also consider security aspects, such as protecting the confidentiality and integrity of the
exchanged data. Encryption, authentication, and access control mechanisms can be implemented to ensure secure
communication between processes.
To make you clear with the diagram of what is API, let’s take a real-life example of an API, you can think of an API
as a waiter in a restaurant who listens to your order request, goes to the chef, takes the food items ordered and
gets back to you with the order. Also, if you want to look for the working of an API with the example, here’s
one. You’re searching for a course(let’s say DSA-Self Paced) on the XYZ website, you send a request(product
search requested) through an API, and the database searches for the course and checks if it’s available, the API is
responsible here to send your request to the database (in search of the course) and responds with the output(best
DSA courses).
What is an API?
API full form is an Application Programming Interface that is a collection of communication protocols and
subroutines used by various programs to communicate between them. A programmer can make use of various API
tools to make their program easier and simpler. Also, an API facilitates programmers with an efficient way to
develop their software programs. Thus api meaning is when an API helps two programs or applications to
communicate with each other by providing them with the necessary tools and functions. It takes the request from
the user and sends it to the service provider and then again sends the result generated from the service provider
to the desired user.
A developer extensively uses APIs in his software to implement various features by using an API call without
writing complex codes for the same. We can create an API for an operating system, database system, hardware
system, JavaScript file, or similar object-oriented files. Also, an API is similar to a GUI(Graphical User Interface)
with one major difference. Unlike GUIs, an application program interface helps software developers to access
web tools while a GUI helps to make a program easier to understand for users.
The API for the Internet protocols
The Internet protocols rely on various APIs (Application Programming Interfaces) to facilitate
communication between networked devices and services. Here are some key APIs used in Internet protocols:
Socket API: The Socket API provides a standardized interface for networking operations at the transport
layer. It enables applications to create, configure, and manage network sockets for communication over
TCP/IP or UDP/IP protocols. Programming languages like C, C++, Java, Python, and many others provide
socket libraries for implementing network communication.
HTTP API: The Hypertext Transfer Protocol (HTTP) API defines a set of methods and status codes for
transferring hypertext documents over the Internet. Web servers and clients use the HTTP API to exchange
requests and responses, allowing users to access and interact with web resources such as web pages, images,
videos, and APIs. Libraries like libcurl in C/C++ or requests in Python provide HTTP client functionality.
RESTful API: Representational State Transfer (REST) is an architectural style for designing networked
applications, often used in conjunction with HTTP. RESTful APIs expose resources as URLs, and clients
interact with these resources using standard HTTP methods (GET, POST, PUT, DELETE). RESTful APIs
are commonly used in web services, cloud computing, and mobile app development.
WebSocket API: The WebSocket API enables bidirectional, full-duplex communication between a client and
a server over a single TCP connection. Unlike traditional HTTP, which follows a request-response model,
WebSocket allows for real-time, low-latency communication, making it suitable for applications such as
chat, online gaming, and real-time data streaming.
DNS API: The Domain Name System (DNS) API provides a mechanism for translating domain names into
IP addresses and vice versa. Applications can use DNS APIs to perform domain name resolution, query
DNS records, and manage DNS configurations programmatically. DNS libraries and utilities are available in
various programming languages for interacting with DNS servers.
SMTP API: The Simple Mail Transfer Protocol (SMTP) API defines a set of commands and responses for
sending and receiving email messages over the Internet. SMTP APIs allow applications to send emails
programmatically by connecting to an SMTP server, authenticating, and transmitting email data according to
the SMTP protocol.
FTP API: The File Transfer Protocol (FTP) API facilitates file transfer operations between a client and a
server over a network connection. FTP APIs support commands for listing directories, uploading files,
downloading files, and managing file permissions on remote FTP servers. Libraries like ftplib in Python
provide FTP client functionality.
UDP Header
UDP header is an 8-byte fixed and simple header, while for TCP it may vary from 20 bytes to 60 bytes. The first 8
Bytes contain all necessary header information and the remaining part consists of data. UDP port number fields are
each 16 bits long, therefore the range for port numbers is defined from 0 to 65535; port number 0 is reserved. Port
numbers help to distinguish different user requests or processes.
UDP Header
1. Source Port: Source Port is a 2 Byte long field used to identify the port number of the source.
2. Destina tion Port: It is a 2 Byte long field, used to identify the port of the destined packet.
3. Length: Length is the length of UDP including the header and the data. It is a 16-bits field.
4. Checksum: Checksum is 2 Bytes long field. It is the 16-bit one’s complement of the one’s complement sum of
the UDP header, the pseudo-header of information from the IP header, and the data, padded with zero octets at
the end (if necessary) to make a multiple of two octets.
Notes – Unlike TCP, the Checksum calculation is not mandatory in UDP. No Error control or flow control is provided
by UDP. Hence UDP depends on IP and ICMP for error reporting. Also UDP provides port numbers so that is can
differentiate between users requests.
Applications of UDP
Used for simple request-response communication when the size of data is less and hence there is lesser
concern about flow and error control.
It is a suitable protocol for multicasting as UDP supports packet switching.
UDP is used for some routing update protocols like RIP(Routing Information Protocol).
Normally used for real-time applications which can not tolerate uneven delays between sections of a
received message.
UDP is widely used in online gaming, where low latency and high-speed communication is essential for a
good gaming experience. Game servers often send small, frequent packets of data to clients, and UDP is well
suited for this type of communication as it is fast and lightweight.
Streaming media applications, such as IPTV, online radio, and video conferencing, use UDP to transmit real-
time audio and video data. The loss of some packets can be tolerated in these applications, as the data is
continuously flowing and does not require retransmission.
VoIP (Voice over Internet Protocol) services, such as Skype and WhatsApp, use UDP for real-time voice
communication. The delay in voice communication can be noticeable if packets are delayed due to congestion
control, so UDP is used to ensure fast and efficient data transmission.
DNS (Domain Name System) also uses UDP for its query/response messages. DNS queries are typically small
and require a quick response time, making UDP a suitable protocol for this application.
DHCP (Dynamic Host Configuration Protocol) uses UDP to dynamically assign IP addresses to devices on a
network. DHCP messages are typically small, and the delay caused by packet loss or retransmission is generally
not critical for this application.
Advantages of UDP
Speed: UDP is faster than TCP because it does not have the overhead of establishing a connection and
ensuring reliable data delivery.
Lower latency: Since there is no connection establishment, there is lower latency and faster response time.
Simplicity: UDP has a simpler protocol design than TCP, making it easier to implement and manage.
Broadcast support: UDP supports broadcasting to multiple recipients, making it useful for applications such
as video streaming and online gaming.
Smaller packet size: UDP uses smaller packet sizes than TCP, which can reduce network congestion and
improve overall network performance.
User Datagram Protocol (UDP) is more efficient in terms of both latency and bandwidth.
Disadvantages of UDP
No reliability: UDP does not guarantee delivery of packets or order of delivery, which can lead to missing or
duplicate data.
No congestion control: UDP does not have congestion control, which means that it can send packets at a rate
that can cause network congestion.
No flow control: UDP does not have flow control, which means that it can overwhelm the receiver with
packets that it cannot handle.
Vulnerable to attacks: UDP is vulnerable to denial-of-service attacks, where an attacker can flood a network
with UDP packets, overwhelming the network and causing it to crash.
Limited use cases: UDP is not suitable for applications that require reliable data delivery, such as email or file
transfers, and is better suited for applications that can tolerate some data loss, such as video streaming or online
gaming.
External data representation and marshalling
External data representation refers to the way data is structured and encoded so that it can be stored or
transmitted in a consistent and standardized manner. Different systems may use different internal
representations for data, but when exchanging data between systems, a common external
representation is needed to ensure compatibility.
Marshalling, also known as serialization or packing, is the process of converting data from its internal
representation to an external representation, and vice versa. This is typically done when data needs to
be transmitted over a network or stored in a file. Marshalling involves encoding the data into a format
that can be easily transmitted or stored, and then decoding it back into its original format at the
receiving end.
The external representation of data can vary depending on the requirements of the system or protocol
being used. Common formats for external data representation include JSON (JavaScript Object Notation),
XML (eXtensible Markup Language), and binary formats like Protocol Buffers or MessagePack.
Marshalling is particularly important when data needs to be exchanged between systems with different
architectures, programming languages, or endianness. By using a standardized external data
representation and marshalling techniques, systems can ensure that data can be accurately interpreted
and processed by different components.
In summary, external data representation and marshalling are crucial for ensuring interoperability and
compatibility between different systems. They involve converting data from its internal representation
to a standardized external format, allowing it to be transmitted, stored, or processed by different
systems.
Unmarshalling: The converse of this process is unmarshalling, which involves reformatting the transferred
data upon arrival to recreate the original data structures at the destination.
Approaches:
There are three ways to successfully communicate between various sorts of data between computers.
1. Common Object Request Broker Architecture (CORBA):
CORBA is a specification defined by the Object Management Group (OMG) that is currently the most
widely used middleware in most distributed systems. It allows systems with diverse architectures,
operating systems, programming languages, and computer hardware to work together. It allows
software applications and their objects to communicate with one another. It is a standard for creating
and using distributed objects. It is made up of five major components. Components and their function
are given below:
Object Request Broker (ORB): It provides a communication infrastructure for the objects to
communicate across a network.
Interface Definition Language (IDL): It is a specification language used to provide an interface in a
software component. To exemplify, it allows communication between software components written in
C++ and Java.
Dynamic Invocation Interface (DII): Using DII, client applications are permitted to use server
objects without even knowing their types at compile time. Here client obtains an instance of a CORBA
object and then invocation requests can be made dynamically on the corresponding object.
Interface Repository (IR): As the name implies, interfaces can be added to the interface repository.
The purpose of IR is that a client should be able to find an object which is not known at compile-time
and information about its interface then request is made to be sent to ORB.
Object Adapter (OA): It is used to access ORB services like object reference generation.
Moreover, objects can be serialized on one platform and deserialized on completely different platforms
as the whole process is JVM independent.
For example, the Java class equivalent to the Person struct defined in CORBA IDL might be:
Java
import java.io.*;
public class Person implements Serializable {
Client-server communication
Client-server concept underpins distributed systems over a couple of decades. There are
two counterparts in the concept: a client and a server. In practice there are often multiple
clients and single server. Clients start communication by sending requests to the server, the
server handles them and usually returns responses back.
Request-reply communication
Sure! There are different types of client-server communication protocols that are commonly
used. Here are a few examples:
2. HTTPS (HTTP Secure): This is a secure version of HTTP that adds encryption to protect
the data exchanged between clients and servers. It's commonly used for sensitive transactions
like online banking or shopping.
3. FTP (File Transfer Protocol): This protocol is used for transferring files between a client
and a server. It allows users to upload, download, and manage files on a remote server.
4. SMTP (Simple Mail Transfer Protocol): SMTP is used for sending and receiving email.
When you send an email, your email client acts as the client and communicates with an email
server using SMTP to deliver the message.
5. DNS (Domain Name System): DNS is not a traditional client-server protocol, but it plays a
crucial role in internet communication. It translates domain names (like snapchat.com) into IP
addresses that computers can understand. This translation is done by DNS servers.
These are just a few examples, and there are many other protocols used for specific purposes
in client-server communication. Each protocol has its own rules and specifications for how
clients and servers should interact and exchange data.
Group communication
A multicast Communication: P1 process communicating with only a group of the process in the system
Unicast Communication : When the host process tries to communicate with a single process in a
distributed system at the same time. Although, same information may be passed to multiple processes.
This works best for two processes communicating as only it has to treat a specific process only. However,
it leads to overheads as it has to find exact process and then exchange information/data.
• Three cases
– Inside object without an observer: send notifications directly to the subscribers
– Inside object with an observer: send notification via the observer to the subscribers
– Outside object (with an observer)
1. An observer queries the object of interest in order to discover when events
occur
2. The observer sends notifications to the subscribers
• Jini
Java Remote interfaces Shape and ShapeList and Java class ShapeListServant implements
interface ShapeList
Java class ShapeListServer with main and Java client of
ShapreList