Distributed System Assignment
Distributed System Assignment
MAY 06,2024
SAMARA, ETHIOPIA
Introduction:
In the realm of computer networking and distributed systems,
various technologies and protocols play crucial roles in
enabling communication between different entities. Remote
Procedure Call (RPC), FTP Client, Name Server, Common
Object Request Broker Architecture (CORBA), and Message-
Oriented Communication (MOC) are fundamental concepts
that facilitate efficient data exchange and interaction in
networked environments.
Remote Procedure Call (RPC)
RPC (Remote Procedure Call) is an inter-process communication technique used in client-server-
based applications. It allows a client to invoke a procedure (subroutine) on a remote server as if it
were a local procedure call. The key points about RPC are:
Client Request: The client sends a request message to the RPC, which translates and forwards
it to the server.
Server Processing: The server processes the request and sends the response back to the client.
Blocking: The client is blocked while the server processes the call.
Example (Java)
import java.net.*;
import java.io.*;
while (true) {
Socket socket =
serverSocket.accept();
System.out.println("Client
connected");
output.println("Response to
client");
socket.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
By running both RPCServer and RPCClient, you can simulate a basic RPC interaction
between a client and a server in Java.
FTP Client
An FTP (File Transfer Protocol) client is a software application that allows users to
connect to an FTP server and perform file operations such as uploading, downloading, and
managing files. FTP clients are commonly used for transferring files between a local machine
and a remote server.
1. FTP Protocol:
o FTP is a standard network protocol used for transferring files over a network.
o It operates on two channels: the command channel (used for sending
commands) and the data channel (used for transferring files).
2. FTP Client Features:
o Connection Management:
Establishing a connection to an FTP server using hostname, port,
username, and password.
Handling passive or active mode connections.
o File Operations:
Uploading files from the local machine to the server.
Downloading files from the server to the local machine.
Renaming, deleting, and moving files on the server.
o Directory Navigation:
Listing directories and files on the server.
Changing the current working directory.
o Security and Authentication:
Supporting secure FTP (SFTP or FTPS) for encrypted communication.
Handling authentication (username/password or SSH keys).
To create a simple FTP client in Java, you can use the Apache Commons Net library,
which provides easy-to-use classes for working with FTP servers. Below is a sample
Java source code that implements an FTP client using Apache Commons Net:
Example:
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
import java.io.FileOutputStream;
import java.io.IOException;
if (ftpClient.retrieveFile(remoteFile, fos)) {
System.out.println("File downloaded
successfully.");
} else {
System.out.println("Failed to download
file.");
}
fos.close();
ftpClient.logout();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (ftpClient.isConnected()) {
ftpClient.disconnect();
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
}
You can run this code after adding the Apache Commons Net library to your project’s
dependencies.
Name Server
A name server, also known as a DNS server (Domain Name System server), is a critical
component of the internet infrastructure. Its primary purpose is to resolve domain names
(such as “example.com”) into IP addresses (such as “192.0.2.1”). When you enter a URL in
your web browser, the name server translates that URL into an IP address, allowing your
browser to connect to the correct web server.
1. DNS Hierarchy:
o The DNS system is organized hierarchically.
o At the top level, there are root servers (represented by “.”), followed by top-
level domains (TLDs) like “.com,” “.org,” and country-code TLDs (e.g., “.us,”
“.uk”).
o Each domain can have subdomains (e.g., “sub.example.com”).
2. Zone Files:
o A name server maintains zone files that map domain names to IP addresses.
o These files contain resource records (RRs) like A records (for IPv4
addresses) and AAAA records (for IPv6 addresses).
3. BIND (Berkeley Internet Name Domain):
o BIND is a widely used open-source DNS server software.
o It runs on Unix-like systems and provides features like caching, zone transfers,
and security.
4. Configuration Steps:
o Configure your name server with zone files for the domains it serves.
o Set up forwarders (other DNS servers to query if your server doesn’t have the
answer).
o Ensure security (e.g., prevent unauthorized zone transfers).
To implement a simple Name Server in Java, you can create a basic server-client
architecture where the server listens for incoming requests from clients and responds
with the corresponding IP address for a given domain name. Below is an example of
Java source code for a simple Name Server:
import java.io.*;
import java.net.*;
while (true) {
Socket socket = serverSocket.accept();
BufferedReader reader = new
BufferedReader(new
InputStreamReader(socket.getInputStream()));
PrintWriter writer = new
PrintWriter(socket.getOutputStream(), true);
writer.println(ip);
socket.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
We create a ServerSocket that listens on port 1234 for incoming client connections.
When a client connects, the server reads the domain name sent by the client.
The getIPForDomain method returns the corresponding IP address for the given
domain name.
The server then sends back the IP address to the client.
This is a very basic example and lacks error handling and proper DNS resolution logic, but it
gives you an idea of how you can start implementing a simple Name Server in Java
To implement Common Object Request Broker Architecture (CORBA) in Java, you can
follow these steps:
1. Define the IDL Interface: The first step is to define the interface using the Interface
Definition Language (IDL). This defines the methods that will be available for remote
invocation.
module HelloWorldApp {
interface HelloWorld {
string sayHello();
};
};
2, Compile the IDL File: Use the idlj tool from the JDK to compile the IDL file and generate the
necessary Java files.
3, Implement the Server: Create a server that implements the generated HelloWorld interface.
import HelloWorldApp.HelloWorldPOA;
}
4 Create the Server Object: Instantiate the server object and register it with the ORB.
import org.omg.CORBA.ORB;
5, Implement the Client: Create a client that will invoke methods on the remote object.
import org.omg.CORBA.ORB;
import HelloWorldApp.HelloWorld;
import HelloWorldApp.HelloWorldHelper;
System.out.println(helloImpl.sayHello());
} catch (Exception e) {
e.printStackTrace();
}
}
}
6. Compile and Run: Compile all your Java files and run the server and client
programs.
7. Start Naming Service: Ensure that a naming service like tnameserv is running
before starting your CORBA application.
This is a basic example of how you can implement CORBA in Java. Remember to handle
exceptions properly and ensure that your environment is set up correctly for CORBA
development.
Message-Oriented Communication (MOC)
Key Points:
o Asynchronous Communication:
Processes send and receive messages independently.
No direct shared memory or procedure calls.
Decoupling of sender and receiver.
o Message Queues:
Processes use message queues to store and retrieve messages.
Queues provide buffering and ensure reliable delivery.
o Publish-Subscribe Model:
Publishers send messages to specific topics or channels.
Subscribers express interest in specific topics and receive relevant
messages.
o Benefits:
Scalability: Handles large numbers of processes.
Loose coupling: Processes can evolve independently.
Fault tolerance: Messages can be stored and retransmitted.
import java.util.ArrayList;
import java.util.List;
subscribers.add(subscriber);
subscriber.receiveMessage(message);
}
Write the Subscriber (MessageSubscriber.java):
@Override
@Override
Usage:
publisher.addSubscriber(new EmailSubscriber());
publisher.addSubscriber(new SMSSubscriber());
publisher.publishMessage("Important update!");
}
Explanation:
Remember to adapt this example to your specific use case. You can extend it by adding more
subscribers or using message queues for scalability and fault tolerance
Summary
Remote Procedure Call (RPC) allows a program to execute code on a remote server as if it
were local, simplifying the development of distributed applications. FTP Client is a software
component that enables users to transfer files between their local system and a remote server
using the File Transfer Protocol (FTP). Name Server is responsible for translating domain
names into IP addresses, facilitating the functioning of the Domain Name System (DNS).
Common Object Request Broker Architecture (CORBA) provides a platform-independent
architecture for distributed object-oriented systems to communicate seamlessly across
different programming languages and hardware platforms. Message-Oriented
Communication (MOC) focuses on asynchronous messaging between distributed
components, ensuring reliable and scalable communication in complex systems.
. References:
1. Tanenbaum, A. S., & Van Steen, M. (2007). Distributed Systems: Principles and
Paradigms. Pearson Education.
2. Orfali, R., Harkey, D., & Edwards, J. (1996). The Essential Distributed Objects
Survival Guide. John Wiley & Sons.
3. Coulouris, G., Dollimore, J., Kindberg, T., & Blair, G. (2011). Distributed Systems:
Concepts and Design. Pearson Education.