Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
22 views

Distributed System Assignment

Uploaded by

Salih Akadar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Distributed System Assignment

Uploaded by

Salih Akadar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

SAMARA UNIVERSITY

COLLAGE OF ENGNEERING AND TECHNOLOGY

DEPARTMENT OF COMPUTER SCIENCE

COURSE: DISTRIBUTED SYSTEM


NAME: SALIH AKADAR ALI
ID NUMBER: SU/1302409

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.*;

public class RPCServer {


public static void main(String[] args) {
try {
ServerSocket serverSocket = new
ServerSocket(5000);
System.out.println("RPC Server is
running...");

while (true) {
Socket socket =
serverSocket.accept();
System.out.println("Client
connected");

BufferedReader input = new


BufferedReader(new
InputStreamReader(socket.getInputStream()));
PrintWriter output = new
PrintWriter(socket.getOutputStream(), true);

String request = input.readLine();


System.out.println("Request
received: " + request);

// Process the request here

output.println("Response to
client");

socket.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}

Explanation:This Java source code provides a simple implementation of a Remote


Procedure Call (RPC) system. The code consists of two classes, RPCServer and RPCClient.
 RPCServer Class: This class represents the server side of the RPC system. It creates
a ServerSocket that listens on port 5000 for incoming client connections. Upon
accepting a connection, it reads the client’s request, processes it (which can be
implemented as needed), and sends a response back to the client.
 RPCClient Class: This class represents the client side of the RPC system. It
establishes a connection to the server running on localhost at port 5000. It sends a
request to the server and then reads and displays the response received from the
server.

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.

Key Concepts and Components:

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).

3, Implementing FTP Client in Java

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;

public class SimpleFTPClient {

public static void main(String[] args) {


String server = "ftp.example.com";
int port = 21;
String user = "username";
String pass = "password";

FTPClient ftpClient = new FTPClient();


try {
ftpClient.connect(server, port);
ftpClient.login(user, pass);
ftpClient.enterLocalPassiveMode();
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);

String remoteFile = "/path/to/remote/file.txt";


FileOutputStream fos = new
FileOutputStream("localfile.txt");

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();
}
}
}
}

In this code snippet:

1. We import the necessary classes from Apache Commons Net library.


2. We establish a connection to the FTP server, login with the provided credentials, set
up passive mode and binary file type.
3. We specify the remote file to download and create a local file output stream.
4. We retrieve the remote file and save it locally.
5. Finally, we handle exceptions and disconnect from the FTP server.

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.

Here are the key points about implementing a name 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).

5. Implementing Name Server in Java

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.*;

public class NameServer {


public static void main(String[] args) {
try {
ServerSocket serverSocket = new
ServerSocket(1234);
System.out.println("Name Server running on port
1234...");

while (true) {
Socket socket = serverSocket.accept();
BufferedReader reader = new
BufferedReader(new
InputStreamReader(socket.getInputStream()));
PrintWriter writer = new
PrintWriter(socket.getOutputStream(), true);

String domain = reader.readLine();


String ip = getIPForDomain(domain);

writer.println(ip);

socket.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}

private static String getIPForDomain(String domain) {


// This is a dummy method, in a real implementation,
you would have a mapping of domain names to IP addresses
if (domain.equals("example.com")) {
return "192.168.1.1";
} else {
return "Domain not found";
}
}
}

In this code snippet:

 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

Common Object Request Broker Architecture (CORBA)

 Definition: CORBA is a specification developed by the Object Management Group


(OMG) to provide interoperability among distributed objects.
 Purpose: It enables communication between objects in different languages and on
different platforms.
 Key Points:
o Middleware: CORBA acts as middleware, allowing systems with diverse
architectures, operating systems, programming languages, and hardware to
work together.
o Transparent Invocation: A client can transparently invoke a method on a
server object, whether it’s on the same machine or across a network.
o Services: CORBA provides services like naming (white pages), trading
(yellow pages), and more.
o Language-Agnostic: CORBA is not tied to a specific programming language.

Implementing CORBA 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.

idlj -fall HelloWorld.idl

3, Implement the Server: Create a server that implements the generated HelloWorld interface.

import HelloWorldApp.HelloWorldPOA;

class HelloWorldImpl extends HelloWorldPOA {

public String sayHello() {

return "Hello, World!";

}
4 Create the Server Object: Instantiate the server object and register it with the ORB.

import org.omg.CORBA.ORB;

public class HelloServer {


public static void main(String[] args) {
try {
ORB orb = ORB.init(args, null);
HelloWorldImpl helloImpl = new HelloWorldImpl();
orb.connect(helloImpl);
orb.run();
} catch (Exception e) {
e.printStackTrace();
}
}

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;

public class HelloClient {


public static void main(String[] args) {
try {
ORB orb = ORB.init(args, null);
org.omg.CORBA.Object objRef =
orb.resolve_initial_references("NameService");
NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);

String name = "Hello";


helloImpl = HelloWorldHelper.narrow(ncRef.resolve_str(name));

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)

Definition: Message-Oriented Communication (MOC) is a communication paradigm in


distributed systems where processes exchange information using messages.

 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.

Example: Simple Java Message-Oriented Communication

Write the Publisher (MessagePublisher.java)

import java.util.ArrayList;

import java.util.List;

public class MessagePublisher {

private List<MessageSubscriber> subscribers = new ArrayList<>();

public void addSubscriber(MessageSubscriber subscriber) {

subscribers.add(subscriber);

public void publishMessage(String message) {

for (MessageSubscriber subscriber : subscribers) {

subscriber.receiveMessage(message);

}
Write the Subscriber (MessageSubscriber.java):

public interface MessageSubscriber {

void receiveMessage(String message);

Create Subscribers (EmailSubscriber.java and SMSSubscriber.java):

public class EmailSubscriber implements MessageSubscriber {

@Override

public void receiveMessage(String message) {

System.out.println("Email received: " + message);

public class SMSSubscriber implements MessageSubscriber {

@Override

public void receiveMessage(String message) {

System.out.println("SMS received: " + message);

Usage:

public class Main {

public static void main(String[] args) {

MessagePublisher publisher = new MessagePublisher();

publisher.addSubscriber(new EmailSubscriber());

publisher.addSubscriber(new SMSSubscriber());

publisher.publishMessage("Important update!");

}
Explanation:

 The MessagePublisher sends messages to subscribers.


 Subscribers (e.g., EmailSubscriber, SMSSubscriber) receive and process messages.
 Loose coupling allows adding new subscribers without modifying existing code.

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.

You might also like