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

Addserverintf - Java: 3) Design and Implement A Simple Client Server Application Using Rmi

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)
53 views3 pages

Addserverintf - Java: 3) Design and Implement A Simple Client Server Application Using Rmi

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

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