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

RMI Client-Server App Implementation

The document describes how to design and implement a simple client-server application using RMI (Remote Method Invocation). It defines an interface AddServerIntf with a method add(int, int) that returns the sum of two integers. It implements this interface in the class AddServerImpl and runs it as a server. The AddClient class looks up and invokes the remote add method, taking two command line arguments and printing the result.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views3 pages

RMI Client-Server App Implementation

The document describes how to design and implement a simple client-server application using RMI (Remote Method Invocation). It defines an interface AddServerIntf with a method add(int, int) that returns the sum of two integers. It implements this interface in the class AddServerImpl and runs it as a server. The AddClient class looks up and invokes the remote add method, taking two command line arguments and printing the result.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

3) Design and implement a simple Client Server Application using RMI.

AddServerIntf.java

import java.rmi.*;
public interface AddServerIntf extends Remote {
int add(int x, int y) throws RemoteException;
}

AddServerImpl.java

import java.rmi.*;
import java.rmi.server.*;
public class AddServerImpl extends UnicastRemoteObject implements AddServerIntf{
public AddServerImpl() throws RemoteException {}
public int add(int x, int y) throws RemoteException {
return x+y;
}
}

AddServer.java

import java.rmi.*;
public class AddServer {
public static void main(String[] args) {
try{
AddServerImpl server = new AddServerImpl();
Naming.rebind("registerme",server);
System.out.println("Server is running...");
} catch (Exception e) {
System.out.println(e);
}
}
}
AddClient.java

import java.rmi.*;
public class AddClient {
public static void main(String[] args) {
try{
AddServerIntf client = (AddServerIntf)Naming.lookup("registerme");
System.out.println("First number is :" + args[0]);
int x = Integer.parseInt(args[0]);
System.out.println("Second number is :" + args[1]);
int y = Integer.parseInt(args[1]);
System.out.println("Sum =" + client.add(x,y));
} catch (Exception e){
System.out.println(e);
}
}
}

Output:

Open a terminal

Navigate to the src folder of your project


In another terminal (while previous one is still running)

Navigate to the src folder of your project

In third terminal (while previous both are still open)

Navigate to the src folder of your project

You might also like