0% found this document useful (0 votes)
10 views3 pages

CN Exp 5

The document outlines the development of a distributed application using Remote Method Invocation (RMI) in Java, detailing its theory, differences from Remote Procedure Call (RPC), and components like stubs and skeletons. It includes an algorithm for a Two-Sum problem, along with the implementation of remote interfaces, server, and client code. The final output confirms the successful development of the application, with an assessment rubric provided for evaluation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views3 pages

CN Exp 5

The document outlines the development of a distributed application using Remote Method Invocation (RMI) in Java, detailing its theory, differences from Remote Procedure Call (RPC), and components like stubs and skeletons. It includes an algorithm for a Two-Sum problem, along with the implementation of remote interfaces, server, and client code. The final output confirms the successful development of the application, with an assessment rubric provided for evaluation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

23IT064

Ex No 5
Distributed Application Development using Remote Method Invocation
Date:
10 Mar 2025

AIM:

To develop a distributed application using Remote Method Invocation

THEORY:

RMI
 RMI allows a Java program to call methods on an object located on another
machine (remotely), as if it were a local object.
 It helps in distributed computing, where different parts of a program can run on
different systems.
Difference between RMI and RPC

RMI (Remote Method RPC (Remote Procedure


Feature
Invocation) Call)
Supports multiple languages
Language Support Java-specific
(C, C++, Python, etc.)
Yes (supports remote No (works with procedural
Object-Oriented
objects) calls)
Uses Java objects & Sends simple data (e.g.,
Communication
serialization integers, strings)
Platform Platform-independent
Can be platform-dependent
Dependency (Java)

Stubs
 A stub is a client-side proxy that represents the remote object.
 When a client calls a method on a remote object, the stub forwards the request
to the actual object on the server.
How It Works:
1. The client calls a method on the stub.
2. The stub sends the request over the network.
3. The server executes the actual method and sends back the result.
Skeletons
 A skeleton is a server-side proxy that receives client requests and passes them
to the actual remote object.
 It helps in handling communication between the stub and the remote
object.
How It Works:
1. The stub sends the request to the server.
2. The skeleton receives the request and calls the actual method.
3. The result is sent back to the stub.

Marshalling / Unmarahalling
 Marshalling = Converting an object into a format (like bytes) to send over the
network.
 Unmarshalling = Converting the received bytes back into an object.

Ex No 3: Server Configuration in CISCO Packet Tracer Page


23IT064

TWO-SUM:
ALGORITHM:
1. Create an empty HashMap (map)
2. Loop through array 'nums' with index 'i':
a. Compute complement = target - nums[i]
b. If complement exists in map:
- Return indices {map[complement], i}
c. Store nums[i] in the map with its index
3. If no pair found, return {-1, -1}

CODING:

1. Remote Interface (TwoSumService.java)


import java.rmi.Remote;
import java.rmi.RemoteException;

public interface TwoSumService extends Remote {


int[] twoSum(int[] nums, int target) throws RemoteException;
}

2. Remote Implementation (TwoSumServiceImpl.java)


import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.HashMap;

public class TwoSumServiceImpl extends UnicastRemoteObject implements TwoSumService {

protected TwoSumServiceImpl() throws RemoteException {


super();
}

@Override
public int[] twoSum(int[] nums, int target) throws RemoteException {
HashMap<Integer, Integer> map = new HashMap<>();
for (int i = 0; i < nums.length; i++) {
int complement = target - nums[i];
if (map.containsKey(complement)) {
return new int[]{map.get(complement), i};
}
map.put(nums[i], i);
}
return new int[]{-1, -1}; // No valid pair found
}
}

3. Server Code (TwoSumServer.java)


import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

public class TwoSumServer {


public static void main(String[] args) {
try {
TwoSumService service = new TwoSumServiceImpl();
Registry registry = LocateRegistry.createRegistry(1099);
registry.rebind("TwoSumService", service);
System.out.println("TwoSumService is running...");
} catch (Exception e) {
e.printStackTrace();

Ex No 3: Server Configuration in CISCO Packet Tracer Page


23IT064

}
}
4. Client Code (TwoSumClient.java)
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.util.Arrays;

public class TwoSumClient {


public static void main(String[] args) {
try {
Registry registry = LocateRegistry.getRegistry("localhost", 1099);
TwoSumService service = (TwoSumService) registry.lookup("TwoSumService");

int[] nums = {2, 7, 11, 15};


int target = 9;
int[] result = service.twoSum(nums, target);

System.out.println("Indices: " + Arrays.toString(result));


} catch (Exception e) {
e.printStackTrace();
}
}
}

OUTPUT:

RESULT:
Thus, the distributed application has been developed using Remote Method Invocation.

Rubrics for Assessment


Parameter Max Marks Marks Obtained
Complexity of the Application 10
Originality of Code 5
Viva-Voce 5
Sub Total 20
Completion of experiment on time 5
Documentation 5
Sub Total 10
Signature of the faculty with Date

Ex No 3: Server Configuration in CISCO Packet Tracer Page

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy